Proshort interview question

Problem no 17 and 142 in leetcode