Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

[Question] Rotate array Left K times and Right K times. #243

Closed
hrj-star opened this issue Oct 20, 2020 · 13 comments
Closed

[Question] Rotate array Left K times and Right K times. #243

hrj-star opened this issue Oct 20, 2020 · 13 comments

Comments

@hrj-star
Copy link
Contributor

hrj-star commented Oct 20, 2020

Problem : Given an array , return its left rotated and right rotated array by K positions.

Sample Input : arr [] =1 2 3 4 5 , K = 5

Output :
Left Rotated array by K=5 times : 1 2 3 4 5
Right Rotated array by K =5 times : 1 2 3 4 5

Sample Input : arr [] =1 2 3 4 5 , K = 4

Left Rotated array by K=4 times : 5 1 2 3 4
Right Rotated array by K =4 times : 2 3 4 5 1

Will implement in Java.

@pranatimittal
Copy link
Contributor

Can you assign it to me for Java?

@prinsusinghal
Copy link

Can you assign it to me for C++?

@Ajordat
Copy link
Contributor

Ajordat commented Oct 20, 2020

Are you sure that's the expected output in that case? To me it looks like it would remain the same in that case, since k equals the length of the array.

Input:
array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 4

Output:
Left-rotated array K(4) times: [4, 5, 6, 7, 8, 9, 0, 1, 2, 3]
Right-rotated array K(4) times: [6, 7, 8, 9, 0, 1, 2, 3, 4, 5]

I will do this in Python.

@hrj-star
Copy link
Contributor Author

Are you sure that's the expected output in that case? To me it looks like it would remain the same in that case, since k equals the length of the array.

Input:
array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 4

Output:
Left-rotated array K(4) times: [4, 5, 6, 7, 8, 9, 0, 1, 2, 3]
Right-rotated array K(4) times: [6, 7, 8, 9, 0, 1, 2, 3, 4, 5]

I will do this in Python.

Yes , there was a typo mistake , the output was for K=4 , have updated , many thanks !

@prinsusinghal
Copy link

Please review my PR: rotate array left k times and right k times. #243 SOLUTION C++ #249

@cyenney
Copy link

cyenney commented Oct 20, 2020

Can you assign to me in C#?

@Ajordat
Copy link
Contributor

Ajordat commented Oct 20, 2020

Added PR #257 to solve this in Python.

@pranatimittal
Copy link
Contributor

Please check PR: #251 for Java Solution

@hrj-star
Copy link
Contributor Author

@aditya109 Dont we have to have to work on PRs after you assign us the issue ?

@aditya109
Copy link
Owner

Hi @pranatimittal @prinsusinghal @Ajordat @hrj-star @cyenney ! Great work on your PR ! If you have not please consider starring this repo to encourage further contributions.

@aditya109
Copy link
Owner

@aditya109 Dont we have to have to work on PRs after you assign us the issue ?

Hi @hrj-star ! No it is not really compulsory. Please raise a PR whenever you see fit.

@pranatimittal
Copy link
Contributor

pranatimittal commented Oct 22, 2020

Thank you @aditya109. Will you please Merge the PR(#263 ) or add hacktoberfest-accepted lable? It will then be counted as one of my PR

@prinsusinghal
Copy link

Please review my PR: rotate array left k times and right k times. #243 SOLUTION C++ #249

Yes @aditya109 do the same with my PR also

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.