As reported: Rubrik CPD intern OA (HackerRank, 75 minutes, 4 questions, 2026), question 1: LeetCode 3072. HackerRank offers no sorted-list container in Python, so a counting structure has to be written by hand.
This is LeetCode 3072 — Distribute Elements Into Two Arrays II.
You are given a 1-indexed integer array nums of length n. Let greaterCount(arr, val) be the number of elements of arr strictly greater than val.
Distribute the elements into two arrays arr1 and arr2 with n operations:
- Operation 1 appends
nums[1]toarr1; operation 2 appendsnums[2]toarr2. - In operation
i(i ≥ 3):- if
greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i]), appendnums[i]toarr1; - if it is smaller, append to
arr2; - if they are equal, append to the array with fewer elements;
- if those are equal too, append to
arr1.
- if
Return result = arr1 + arr2 (concatenated).
Example 1
nums = [2,1,3,3] -> [2,3,1,3]
arr1 = [2], arr2 = [1]. For 3: both counts are 0 and both arrays have one element → arr1 = [2,3]. For the last 3: both counts are 0, arr2 is shorter → arr2 = [1,3].
Example 2
nums = [5,14,3,1,2] -> [5,3,1,2,14]
Constraints: 3 ≤ n ≤ 10^5; 1 ≤ nums[i] ≤ 10^9.
Code runner format: one line holding nums as a JSON array (LeetCode's test-case format). Implement resultArray(nums); the harness prints the result array.