Company: KKR_Bank
Difficulty: medium
Split Array into Two Unique Halves Problem Description Given an array of integers a , of even length, your task is to split it into two arrays of equal length such that all the numbers are unique in each of them. There may be more than one possible answer. In which case you may return any of them. If there are no possible answers, return an empty array. Hint: Count the number of occurrences of each integer in a . If there are integers occurring more than twice, then there is no solution. Next, put the integers occurring twice into both answer arrays. Finally, put all other numbers in the answer arrays, following the condition that they should have equal sizes. Examples Example 1: Input: a = [1, 2, 3, 4] Output: [[1, 3], [2, 4]] Explanation: Answers like [[1, 2], [3, 4]] or [[4, 2], [3, 1]] would also be considered correct. Example 2: Input: a = [1, 1, 2, 1] Output: [[1, 2], [1, 1]] Explanation: Again, there are other possible answers. Example 3: Input: a = [2, 2, 3, 3, 2, 2] Output: []