You are given a 1-indexed array of distinct integers nums of length n. You need to distribute all the elements of nums between two arrays arr1 and arr2 using n operations. In the first operation, append nums[1] to arr1. In the second operation, append nums[2] to arr2. Afterwards, in the ith operation: - If the last element of arr1 is greater than the last element of arr2, append nums[i] to arr1. Otherwise, append nums[i] to arr2. The array result is formed by concatenating the arrays arr1 and arr2. For example, if arr1 == [1,2,3] and arr2 == [4,5,6], then result = [1,2,3,4,5,6]. Return the array result.
Example 1
Input: nums = [2,1,3]
Output: [2,3,1]
Explanation: Seed arr1=[2], arr2=[1]. For nums[2]=3, tail of arr1 (2) > tail of arr2 (1), so append to arr1 → arr1=[2,3]. Concatenating gives [2,3,1].
Example 2
Input: nums = [5,4,3,8]
Output: [5,3,4,8]
Explanation: Start with arr1 = [5] and arr2 = [4]. For 3, the last of arr1 (5) is greater than the last of arr2 (4), so arr1 = [5,3]. For 8, the last of arr1 (3) is not greater than 4, so arr2 = [4,8]. Concatenating gives [5,3,4,8].
Example 3
Input: nums = [1,2,3]
Output: [1,2,3]
Explanation: Minimal length. arr1=[1], arr2=[2]; nums[2]=3 goes to arr2 since 1 is not > 2 → arr2=[2,3].
Follow the rules literally: seed arr1 and arr2 with the first two elements, then route each remaining element to whichever array currently has the larger tail.
Run checks all cases above. Submit evaluates all test cases.