Meta interview question

basic algo question and 2nd one is more difficult