Baker Hughes Interview Question

They asked me to solve one DSA problem which was around leetcode tough.