Solve array duplicates and two-type subarray | Amazon Coding Question