Atlassian interview question

standard leet code (medium difficulty)