-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highlevel-1
71 lines (55 loc) · 1.28 KB
/
Highlevel-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# def rotate(arr,d):
# i=0
# j=d
# remaining_nums = len(arr)-d
# while remaining_nums >= d:
# k=1
# while k<=d:
# arr[i], arr[j] = arr[j],arr[i]
# i+=1
# j+=1
# k += 1
# remaining_nums = len(arr) - j+1
# if j == len(arr): return arr
# while remaining_nums > 0:
# k=i
# curr_num = arr[j]
# curr_index = j
# while k<d+i:
# arr[k],arr[k+1] = arr[k+1],arr[k]
# k += 1
# arr[curr_index] = curr_num
# j += 1
# i += 1
# remaining_nums -= 1
def rotate(arr,d):
actual_d = d%len(arr)
i=0
while actual_d > 0:
k=i
while k<len(arr)-1:
arr[k],arr[k+1] = arr[k+1],arr[k]
k += 1
actual_d -= 1
i += 1
return arr
print(rotate([1,2,3,4,5,6,7,8,9,10],17))
# [1,2,3,4] 5/4
# [2,3,4,1]
# [3,4,1,2]
# []
# rotate([1,2,3,4,5,6,7,8,9,10],13)
# # let arr = [1,2,3,4,5];
# # let d = 2;
# # [1,2,3,4,5]
# # [3,4,1,2,5]
# # [3,4,5,1,2]
# # [3,4,1,2,5]
# # [3,2,1,4,5]
# # [3,4,1,2,5,6,7]
# # [3,4,5,6,1,2,3,7,8]
# # [3,4,5,6,7,1,2,3,8]
# # [3,4,5,6,7,1,2,3,8]
# # [3,4,5,6,7,2,3,2,8]
# # [3,4,5,6,7,1,2]
# # [3,4,1,]