Problem ¡ Array

Distribute Integers Between Arrays

Learn this problem
● EasyZipRecruiterINTERNOA

Problem statement

Feel free to checkout the image source below for the original problem statement 🐝

Once upon a time, there was an array of integers called "numbers," and the task was to divide these numbers between two special arrays, "first" and "second." However, the division wasn’t random—it followed a set of magical rules. The journey began with the very first number, numbers[0], which was gently placed into the first array. The second number, numbers[1], found its home in the second array. But for every number that followed, starting from numbers[2] and beyond, things became a bit more interesting. Each new number had to find the array where it would be happiest. How was that decided? Well, the number would go to the array that had more elements strictly greater than itself. It was drawn to where the bigger numbers lived! However, if both arrays had the same number of elements greater than the new number, it would choose the array that had fewer elements, preferring to balance things out. And if, after all of that, the arrays were still tied, the number would finally choose the first array as its home. Your quest is to complete the story by combining both arrays into one, with all the numbers from second gracefully appended to the end of first. This combined array will be your final answer. Now go forth and divide the numbers according to these magical rules, returning the grand combination of first and second!

Function

ziprecruiterDistributeIntegersBetweenArrays(numbers: int[]) → int[]

Examples

Example 1

numbers = [5, 7, 6, 9, 2]return = [5, 9, 2, 7, 6]

Start with first = [5] and second = [7]. For 6, the second array has one greater element while the first has none, so append 6 to second. For 9, both greater counts are zero, so append it to the shorter first array. For 2, both arrays contain two greater elements and have equal lengths, so append it to first.

The final arrays are first = [5, 9, 2] and second = [7, 6], producing [5, 9, 2, 7, 6].

Constraints

Unknown for now

More ZipRecruiter problems

drafts saved locally
public int[] ziprecruiterDistributeIntegersBetweenArrays(int[] numbers) {
  // write your code here
}
numbers[5, 7, 6, 9, 2]
expected[5, 9, 2, 7, 6]
checking account