Applied Intuition interview question

Medium leetcode style questions + how would you design this algorithm