Rotate Array | Leetcode 189 | Top 150 interview question series

preview_player
Показать описание
Top 150 interview question series
Rotate Array
Leetcode problem number 189

JAVA interview programming playlist:
Рекомендации по теме
Комментарии
Автор

Time complexity: O(n)
Space complexity: O(1)

public class Solution {
public void Rotate(int[] nums, int k) {
int n=nums.Length;
k=k%n;
swap(nums, 0, n-k-1);
swap(nums, n-k, n-1);
swap(nums, 0, n-1);
}
private void swap(int[] nums, int left, int right)
{
while(left<right)
{
var temp=nums[left];
nums[left]=nums[right];
nums[right]=temp;
left++;
right--;
}
}
}

dibyendusaha
Автор

Hello mam,
I don't know how to thank you because you are amazing,
The way you teach, the way you solve the problems, applying the approach is much easier even for hard problems,
Thank you so much mam for this amazing

yashvardhansingh
Автор

Mam please continue your leetcode problem series . it will helpful for us

swastikkumar
Автор

Ma'am, you are the best teacher in YouTube, please solve the top 150 DSA problem in Java ASAP, And it will help us to crack Interview. Thank you ma'am

MohibulIslam-mz
Автор

Thank you for detailed information. It was really helpful !!!

sachinpatil
Автор

mene bhoot vedio dekh liye lekin nhi hua mujse i think i quit nd i got your vedio and now i easily solve thnxxx a lot mam ❤❤❤❤❤❤

Heavy-coder
Автор

Really Really thank you so much mam, really appreciated your work

kaka_goat
Автор

Please do continue with the series, In entire you tube this is the only channel where I am able to understand the solution and co-relate with my approach. I understand because of medical condition you took a break, but please try uploading the videos as soon as possible please Amrita it's my humble request.

And if you are not well, Get well soon and then upload the videos.

adityarajsah
Автор

Please continue your Leet code problem series . it will helpful for us

raneshmitra
Автор

please continue the series of the this playlist it helps us alot

aasimahsan
Автор

Excellent explanation mam, please post the problem solving videos mam ❤

AnbuAnbu-xjbx
Автор

idk but this is simpler: public static void rotate(int[] nums, int k) {
int n = nums.length;
k = k % n;

int[] lastElements = Arrays.copyOfRange(nums, n - k, n);
int[] firstElements = Arrays.copyOfRange(nums, 0, n - k);

System.arraycopy(lastElements, 0, nums, 0, lastElements.length);
System.arraycopy(firstElements, 0, nums, lastElements.length, firstElements.length);
}

LinhTran-omqh
Автор

why did you stop? can you put your linkedin

lesaplmansion
Автор

Can any one say what to change in the code if i want it rotate by left

nirajvarma-zd
Автор

i know we are taking k=k%n for out of bound exceptions but why . i mean how k=k%n can help in this situation??

aniket
Автор

please continue your leetcode problems series

Mohd.FaisalKhan-ooqj
Автор

Why have you guys stopped posting solutions?

CodingJoySoul
Автор

Please continue the 150 questions series please maam

PallabChatterjee
Автор

Hello, could you please post those questions only

webtestingui
Автор

What happened to you amrita didi we really miss your concepts

brp