easy solution, both works fine, but this takes less time
Complexity
Time complexity:
O(N2)
Space complexity:
O(N)Code

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N2)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N)
# Code
```python3 []
class Solution:
    def resultArray(self, nums: List[int]) -> List[int]:
        n = len(nums)
        # n1 = [nums[0]]
        # n2 = [nums[1]]
        # def greater_count(array, value):
        #     k = 0
        #     for j in array:
        #         if j > value:
        #             k+=1
        #     return k
        # for i in range(2,n):
        #     if greater_count(n1, nums[i]) > greater_count(n2, nums[i]):
        #         n1.append(nums[i])
        #     elif greater_count(n1, nums[i]) == greater_count(n2, nums[i]):
        #         if len(n1) > len(n2):
        #             n2.append(nums[i])
        #         elif len(n1) == len(n2):
        #             n1.append(nums[i])
        #         else:
        #             n1.append(nums[i])
        #     else:
        #         n2.append(nums[i])
        # return n1+n2
        n1, n2, sorted1, sorted2 = [nums[0]],[nums[1]], [nums[0]], [nums[1]]
        for i in range(2, len(nums)):
            val = nums[i]
            index1, index2 = bisect.bisect_right(sorted1, val), bisect.bisect_right(sorted2, val)
            count1, count2 = len(n1) - index1, len(n2) - index2
            if count1>count2 or(count1 == count2 and len(n1)<= len(n2)):
                n1.append(val)
                sorted1.insert(index1,val)
            else:
                n2.append(val)
                sorted2.insert(index2, val)
        return n1+n2
            
```
['Python3']