Rotate Array | LeetCode 189 (Reverse Method) | Coding Interview Tutorial

preview_player
Показать описание
Rotate Array solution: LeetCode 189

AFFILIATE LINKS
If you're interested in learning algorithms, these are great resources.

💲 All coupons and discounts 💲

Rotate Array | LeetCode 189 (Reverse Method) | Coding Interview
#rotatearray #leetcode #algorithms #terriblewhiteboard #codinginterview

Click the time stamp to jump to different parts of the video.
00:00 Title
00:07 Problem readout
01:11 Whiteboard solution
04:34 Coding solution
08:22 Result and outro
Рекомендации по теме
Комментарии
Автор

If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

TerribleWhiteboard
Автор

This is a great explanation. You explained in beautifully. Nice work.

simoneanthony
Автор

i love your explanations and videos. subscribed!

juanceja
Автор

This is truly clever solution. It's simple, easy to understand and it works.

kamcipako
Автор

Great explanation. I noticed on leet code the difficulty is medium but in your video it shows easy.

sogggy
Автор

I was asked this question during a job interview for a Java Spring Boot CRUD service developer. I asked the interviewer when this would ever be applicable to a REST service and do you really expect a developer here to be doing stuff like this regularly. He laughed and said no, the job is just exposing databases so nothing like this would ever appear and he doesn't even think anything like this would ever even appear in the work the head architecture/platform team is doing. I said why are you asking me this then.... He then changed the subject and started asking me a riddle about marbles.... I never knew Spring Boot was powered by marble riddles....

Yeah - I ended up turning them down and am working for a company that actually respected my time. So was very curious about this question and looked it up. Good overview here!

UpBebop
Автор

Lines 19 & 20 can be included in 17 & 18 as Super clear explanation, thank you!

tl
Автор

Excellent video. Thank you very much. If I understood correctly, the code `k = k % nums.length;` is just an optimization, to rotate less. But if we don't do this optimization, it doesn't work for the input `[-1], 2`. I don't get this. Isn't the code `k = k % nums.length;` just to increase performance?

leongrin
Автор

JavaScript lets you swap 2 numbers like this: [nums[start], nums[end]] = [nums[end], nums[start]]

raymond
Автор

I don`t understand this line of code k = k % array.length

Everytime i checked k after this line of code, k equals to initial k in the function, so why we need to write it?

ЖИЗНЬРУССКОГОИТАЙКИ
Автор

How can we think of solution like this ourselves? Do these sorts of patterns come up often? Doesn't seem intuitive

colesiegel
Автор

6:38 hAaAVvE TooOO ...great video by the way

algorithmtrader
Автор

can we just pop the last few elements and shift it to the front?

renetchi
Автор

what is the point of memorizing this solution? I dont think anyone will care even if I come up with this solution. For sure they will figure out I have seen this earlier. The whole point of interview should be to check my thought process and how i am approaching the problem.

amitzala
Автор

i solved this, i know because i printed Nums but it still wont accept the answer. and its O(1). The only reason I could see if that I used a temp list however at the end I did nums = temp so whats the problem?

l = len(nums)
temp = nums[l-k:l]
nums= temp + nums[0:l-k]

nums = temp

print nums

Kaodusanya
Автор

Isn't creating additional function causes space complexity to increase, so it's not O(1) anymore?

fanone