Java Program to left rotate the elements of an array

preview_player
Показать описание
In this video, I have explained how to rotate the elements of the array to left by the 'n' position.
----------------------------------------------------------------------------
If you are facing any problem comment it down, I'll try my best to solve it:)
----------------------------------------------------------------------------
If you any doubts you can contact me :
Instagram: @muradalimj
------------------------------------------------------------------------
------------------------------------------------------------------------
-------------------------------------------------------------------------------
LIKE SHARE & SUBSCRIBE MY CHANNEL
-------------------------------------------------------------------------------
THANK YOU
-------------------------------------------------------------------------------
CODE WITH MURAD
Рекомендации по теме
Комментарии
Автор

Great Explanation Keep Updating with Array problesm

srivardhankandike
Автор

Time complexity is O(n*n). If u want O(n) use reverse logic.

shawkishor
Автор

Thank you for helping me preparing for my exam!

richardbaba
Автор

Great explanation, thanks brother for make the code easy

sangramswain
Автор

Great bro!!! the way u explained the concept was very good and i hope u make videos on oops and other concepts like in Java.

inksquare
Автор

Time complexity: 0(n), Space Complexity: 0(1)
class Solution {
void reverse(int arr[], int start, int end){
int i = start, j = end;
while(i<=j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
void leftRotate(int[] arr, int n, int d) {
// code here
d = d % n;
reverse(arr, 0, d-1);
reverse(arr, d, n-1);
reverse(arr, 0, n-1);

}
}

amitkumar-sqf
Автор

It is correct solution but it does not pass the time complexity test case

karthikeyenguruswamy
join shbcf.ru