Snap Interview Question

leetcode 212 hard problem. They expect QA engineers to solve this in 25 min.