Freshworks interview question

Leetcode medium and hard.