using a sorted set gives excellent performance
fixed tests
generalized solution to n size spaces