Simple JavaScript solution
Code\n\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar binarySearch = function (arr, val) {\n    let start = 0, \n        end = arr.length - 1,
# Code\n```\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar binarySearch = function (arr, val) {\n    let start = 0, \n        end = arr.length - 1,\n        mid = Math.floor((start + end) / 2)\n    while (start < end) {\n        if (arr[mid] > val) {\n            end = mid - 1    \n        } else {\n            start = mid + 1 \n        }\n        mid = Math.floor((start + end) / 2)\n    }\n    if (arr[start] <= val) {\n        start++;\n    }\n    return [arr.length - start, start]\n}\n\nvar resultArray = function(nums) {\n     const arr1 = [nums[0]],\n           arr2 = [nums[1]]\n     let sortedArr1 = [nums[0]],\n         sortedArr2 = [nums[1]]\n     for (let i = 2; i < nums.length; i++) {\n         const n = nums[i],\n               [gc1, s1] = binarySearch(sortedArr1, n),\n               [gc2, s2] = binarySearch(sortedArr2, n)\n         if (gc1 > gc2) {\n             arr1.push(n)\n             sortedArr1.splice(s1, 0, n)\n         } else if (gc2 > gc1) {\n             arr2.push(n)\n             sortedArr2.splice(s2, 0, n)\n         } else if (arr2.length < arr1.length){\n             arr2.push(n)\n             sortedArr2.splice(s2, 0, n)\n         } else {\n             arr1.push(n)\n             sortedArr1.splice(s1, 0, n)\n         }\n     }\n    return [...arr1, ...arr2]\n};\n```
['Array', 'Binary Search', 'JavaScript']