BlackRock interview question

Leetcode question at medium level