LeetCode 189: Rotate Array - Interview Prep Ep 52

preview_player
Показать описание


⭐ Support my channel and connect with me:

Solutions explained:

Solution1: we could use a nested for loop, rotate every single element to the right one at a time, total k times, this could potential results in TLE (Time Limit Exceeded exception on LeetCode OJ), time complexity: O(n*k), space complexity: O(1);
Solution 2: we could trade off space for time: use an extra array to help, assign all elements into its final correct position in the extra array, then copy the extra array into the input array. Time: O(n), Space: O(n);
Solution 3: we could reverse the input array three times:
1. first reverse this entire array,
2. secondly, reverse the array from 0 to k - 1
3. lastly, reverse the array from k to length - 1
Time: O(n), Space: O(1)

// TOOLS THAT I USE:

// MY FAVORITE BOOKS:

My ENTIRE Programming Equipment and Computer Science Bookshelf:

And make sure you subscribe to my channel!

#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures

Your comments/thoughts/questions/advice will be greatly appreciated!
Рекомендации по теме
Комментарии
Автор

Love how you move from brute force, to more optimal solutions all the while explaining.

geekboy
Автор

Absolutely the best explanation I could ever find on youtube!

melanieprevot
Автор

your explanation is so clean and understandable man, thank you!!

exe
Автор

Actual explanations! Best one I’ve seen so far

caizza
Автор

Such a fantastic explanation. I gone through multiple channel for the same problem. Everyone jump straight to the optimal solution. He gave the best explanation from brute force to optimal. Thank you so much for sharing your knowledge to he whole world. Keep doing this good work.

mamu
Автор

Finally found normal explanation of reverse solution thanks

muradsatimov
Автор

You're God in explaining these problems bro. Loved it.💯

entertainmentadda
Автор

amazing! Best explanation so far. Thank you so much and hope to see more video like this!

annieonee
Автор

That was amazin explanation. Thank you!

VileHint
Автор

Thank you, your method is really better and helpful to me.

kellyyang
Автор

Nice and detailed explanation! Some other videos just skip many steps they think are obvious, I think that is not helpful for beginners, but yours are great!

alexcuenca
Автор

Thank-you so much for such a wonderful explanation sir, you are too good, please make more and more videos like this so people like us can achieve our dreams, God bless you :)

saileshramesh
Автор

Wonderful Explanation! Thank you for the help.

sudhakarg
Автор

Thanks for the great content keep it up

AhmedHemaz
Автор

Thanks a lot, you explained really well!

sakshiramsinghani
Автор

can you tell me what is clockwise and counterclockwise rotation in terms of left and right rotation? i am really confused.

amisha
Автор

hey dave, great content! what distro are you using?

exceltokenizer
Автор

this leetcode grind is hard i dont think i can do this

andretheruler