0

Write an algorithm that rotates a given array, Scenario

Write an algorithm that rotates a given array, Scenario Give an array b = [2,3,4,5] and rotation distance d = 2; when b is passed through rotation function myFunctions(arr: [Int], dist:Int) myFunction(arr: b, dist: d) result should should be [4, 5, 2, 3] the result can be printed or returned

10th Aug 2022, 8:19 AM
Hope Mwale
Hope Mwale - avatar
4 odpowiedzi
+ 5
Hope Mwale , can you please complete your question by using a tag with the name of the required programming language ?
10th Aug 2022, 11:08 AM
Lothar
Lothar - avatar
+ 3
Hope Mwale You have to post your try...
10th Aug 2022, 8:28 AM
KrOW
KrOW - avatar
+ 2
I advise you to look at the modulo operator, it can be useful here. You have to put a variable going from dist to (arr.size + dist - 1), and then adapt this variable to match with the array indexes
10th Aug 2022, 9:28 AM
Arthur Le Floch
+ 1
First show your try!
10th Aug 2022, 3:44 PM
Crash
Crash - avatar