Sample Problem 1

Create A balanceArrays Function

Problem

Write a Java function called balanceArrays that takes a two dimensional array of integers and returns a new two dimensional array of integers where all of the values from the original array are equally distributed across second dimension of the array.

Input

A two-dimensional array of integers.  The arrays in the first dimension (an array of integer arrays) can be any length. Each of the individual arrays in the second dimension can be of different lengths.

Output  

A new array with the same number of arrays in the first dimension as the input. The output differs from the input in the second dimension. All of the individual arrays in the second dimension will have the same length, and the original values will adjust to fill the new arrays.

Sample

Input

[[ 1, 2, 3, 4 ],
 [ 5, 6, 7, 8, 9, 10 ],
 [ 11, 12, 13, 14, 15 ],
 [ 16, 17, 18 ],
 [ 19, 20, 21, 22, 23, 24, 25 ]]

Output

[[ 1, 2, 3, 4, 5 ],
 [ 6, 7, 8, 9, 10 ],
 [ 11, 12, 13, 14, 15 ],
 [ 16, 17, 18, 19, 20 ],
 [ 21, 22, 23, 24, 25 ]]

© 2024 Code..Begin!