BNY interview question

Triple Hackerrank Algorithm question they have asked