Left Rotation | HackerRank | Python | Data structure | Array | Interview

preview_player
Показать описание
This video is about HackerRank Left Rotation problem.
A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2].
Given an array of n integers and a number, d, perform d left rotations on the array. Then print the updated array as a single line of space-separated integers.

Follow us on:
Whatsapp:
Telegram:

For Python homework help visit our sponsor site

For 1 to 1 Python Tutoring

Facebook:

Linkedin:

Instagram:

#HackerRank #Array #DataStructure #Interview
Рекомендации по теме
Комментарии
Автор

Hey Programmer/Learner, if you have any better solution feel free to post in comment section.

codingcart
Автор

I have never seen such nice explanation of problems!

abhilashrudra
Автор

A very easy and simple solution that works is this:
for i in range(d):
a.append(a.pop(0))
return a

itswiftyy
Автор

great comeback, better is a[d:] + a[0:d]

shubhamkumarrohit
Автор

beautiful and simple thinking and teaching :) thanks!

zedor
Автор

Wow man. The last trick was simply awesome

tanmaytomar
Автор

waaoo such a great logic thank u sooo much sir

loveysingh
Автор

i have tried to make it simple...it is working..
list1 = [0] * len(arr)
for i in range(len(arr)):
list1[i - d] = arr[i]
return list1

shaktiprasannapani
Автор

sir this video is simply awesome but please tell me how you make this logic ? how i came to know that now i have to do (n+d)%n how u came across this logic and how to made it please tell us so we can do question from our own!! thanks and a very good explanation thank you

sahilbisht
Автор

Also plz check out New Year preparation kit-->new year chaos)

soumyakantibanerjee_
Автор

Why can't we use range(d%n)? if d=n=10^5 then loop won't execute

chitneedihemanthsaikumar
Автор

What is rstrip?? And why u r taking for _ ??

hellyshah
Автор

i think index=n-(k%n) and retturn index will pass all the test cases

NCCSAyesha
Автор

How can I unpack using function? Since I have to end it with return statement I am unable to unpack it.

urmigori
Автор

what does it mean: a=a[1:]+a[0:1]? Can you explain me?

hollday
Автор

I guess one thing is to also keep in mind, if the length of list equals the rotations, it will put back the list as is, so just returned it.

sorrowseal
Автор

what can we do if they give in the form of recursion like
def rotLeft(a,  d):
if __name__ == '__main__':

sivapriya
Автор

Plz make a vedio on perfection quotients problem euler-->#241perfection quotients)..I don't know python☹️ can u plzz solve it in Java🙏🙏

soumyakantibanerjee_
Автор

Looks like you can use a[d%n:] + a[0:d%n] and get the same result because (d+n)%n is the same as d%n.

benjaminmoon
Автор

simply type -- return (arr[d:]+arr[:d])

gamingtweaks