NVIDIA interview question

Standard algorithmic question as on leetcode