Art of Problem Solving interview question

One puzzle solving question and another JavaScript based question