Question: Method takes a two-dimensional array and converts it into a regular one-dimensional array. The new one-dimensional array is returned from the method. If the original
Method takes a two-dimensional array and converts it into a regular one-dimensional array. The new one-dimensional array is returned from the method.
If the original array is empty, an empty array must be returned.
The assumption is that all rows of the original array are of the same length.
Examples:
int[][] a= {{1, 2, 3},
{4, 5, 6}, => {1, 2, 3, 4, 5, 6, 7, 8, 9}
{7, 8, 9}};
int[][] a= {{1, 2, 3},
{4, 5, 6}} => {1, 2, 3, 4, 5, 6}
int[][] a= { } => { }
Efficiency requirements
- Do not use any additional data structures, ArrayLists, collections etc. for temporary storage. Only one array must be allocated - the one that will be returned from the method.
- You must write code that passes only once through all the elements of the original array.
Add Doc comments before the method header.
Step by Step Solution
There are 3 Steps involved in it
heres the code with explanations for converting a 2D array to a 1D array efficiently This method takes a twodimensional array and flattens it into a o... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
663dc3806be80_962362.pdf
180 KBs PDF File
663dc3806be80_962362.docx
120 KBs Word File
