Okta interview question

It is a LeetCode medium question