Applied Intuition Interview Question

Leetcode problem in between medium and hard