Tredence interview question

Leetcode Hard question in DSA OT round