Google Interview Question

It was an array related problem. Leetcode medium. Was asked to explain the code, time complexity and space complexity as well