Windsurf Interview Question

Leetcode style algorithm question. It was hard.