Applied Intuition interview question

Leetcode problem in between medium and hard