Okta Interview Question

Leetcode medium question, solvable within 30 minutes or so.