Adobe interview question

DSA questions- medium difficulty