Solution to facebook hacker cup qualification round problems