Publicis Sapient interview question

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