Publicis Sapient Interview Question

A leetcode array medium, it was easy had to write the code in an online compiler