Find all balanced k in a permutation | Microsoft Coding Question