Binary search
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport bisect \ndef solve(arr):\n    arr1, arr2 = [arr[0]], [arr[1]]\n    sorted1, sorted2 = [arr[0]], [arr[1]]\n    for i in range(2, len(arr)): \n        idx1 =  bisect.bisect_right(sorted1, arr[i])\n        idx2 =  bisect.bisect_right(sorted2, arr[i])    \n        cnt1 = len(arr1) - bisect.bisect_right(sorted1, arr[i])\n        cnt2 = len(arr2) - bisect.bisect_right(sorted2, arr[i])\n        if cnt1 > cnt2 or ((cnt2 == cnt1) and len(arr1) <= len(arr2)):\n            arr1.append(arr[i])\n            sorted1.insert(idx1, arr[i])\n        else:\n            arr2.append(arr[i])\n            sorted2.insert(idx2, arr[i])\n            \n    return arr1 + arr2\nclass Solution:\n    def resultArray(self, nums: List[int]) -> List[int]:\n        return solve(nums)\n```
['Python3']