100% beats with ts
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```\nfunction resultArray(nums: number[]): number[] {\n  // put the frequency data into a PriorityQueue\n  const arr1 = [nums[0]], arr2 = [nums[1]];\n\n  let sortedArr1 = [...arr1], sortedArr2 = [...arr2];\n  // len > 3\n  const len = nums.length;\n  for (let i = 2; i < len; i++) {\n    const n = nums[i];\n    const idx1 = findFirstBigger(sortedArr1, n);\n    const idx2 = findFirstBigger(sortedArr2, n);\n    if (arr1.length - idx1 < arr2.length - idx2) {\n      arr2.push(n);\n      sortedArr2.splice(idx2, 0, n)\n    } else if(arr1.length - idx1 > arr2.length - idx2) {\n      arr1.push(n);\n      sortedArr1.splice(idx1, 0, n);\n    } else {\n      if (arr1.length > arr2.length) {\n        arr2.push(n);\n        sortedArr2.splice(idx2, 0, n)\n      } else {\n        arr1.push(n);\n        sortedArr1.splice(idx1, 0, n);\n      }\n    }\n  }\n  return arr1.concat(arr2);\n};\n\nfunction findFirstBigger(arr: number[], n: number) {\n  let l = 0, r = arr.length - 1;\n  let res = Infinity;\n  while (l <= r) {\n    const mid = Math.floor((l + r) / 2);\n    if (arr[mid] <= n) {\n      l = mid + 1;\n    } else if (arr[mid] > n) {\n      r = mid - 1;\n      res = mid;\n    }\n  }\n  return res;\n}\n\n```
['TypeScript']