Google interview question

Medium LC similar to 2 pointer question