multi-dimensional array challenge – convert all rows to columns and columns to rows using Java

convert-all-rows-to-columns-and-columns-to-rows

Welcome to the Practice House, In this post, we are going to solve a problem or a challenge for multi-dimensional Array. it’s called Convert All Rows to Columns and Columns to Rows.

So what is the multi-dimensional Array? To learn more about array and multidimensional array you may google it a bit. This challenge I got from HackerEarth while studying about Data Structure.

So our Scenario will be

sample input and output for multidimensional array

 

TEST YOUR UNDERSTANDING

We will have to create a 2D array and our task is to convert all rows to columns and columns to rows.
Input:
The first line contains 2 integers, N – total rows, M – total columns. here we got 3 rows and 5 columns.

Output:
Print  5 rows and 3 columns value as shown above image.

Okay Now let’s check our my solutions how i did it.

Our Code Snippet :

 

Our Console Output:

Here I showed the example with 3 rows and 5 columns so I needed to key in 15 values. You can try with small values.

Conclusion

Congratulations we have made it. So we learned how to take input and how to create the array and then we convert that array in a new array. That’s great, isn’t it? Let me know your thought about this problem. The source code will be available in my Github. So feel free check it out and improve it.

Thank you so much for visiting us.

Leave a Reply

avatar
  Subscribe  
Notify of