implemented getClosestState by using a set sorted by size.