Selasa, 27 Juli 2021

How to Reverse Array in Place in Java? Solution With Explanation

Reversing an array sounds pretty easy, isn't it? It does sound like that, because all you need to do is create an array of the same size, iterate through the original array from end to start, and populate your new array. Boom!!, you have got an array that has elements in reverse order of the original array, but the problem is you have used an additional array here, which makes space complexity of your solution O(n). You cannot use this solution if the array is big e.g. an array of 10 million orders and you don't have enough heap space available.

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon