Improbable Interview Question

Leetcode style medium problem, array based