Grainger Interview Question

Leetcode question was given .