Hive (CA) interview question

They asked a LeetCode-style question of medium difficulty.