Improbable interview question

Leetcode style medium problem, array based