Grainger interview question

Leetcode question was given .