space-efficient solutions