Skip to content

Commit 54049a1

Browse files
authored
Add files via upload
1 parent d98e08f commit 54049a1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Circulararrayrotation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Circular rotation of an array by k elements
2+
#This means that each element shifts by k positions
3+
4+
def circularrotation(num:list[int],k:int):
5+
n=len(num)
6+
num2=[0]*n
7+
for i in range(len(num)):
8+
if(i+k)<len(num):
9+
num2[i+k]=num[i]
10+
else:
11+
num2[(k+i)-n]=num[i]#To handle values greater than the length of array
12+
return num2
13+
print(circularrotation([1,2,3,4,5,6,7],3))

ReplacewithRank.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Write code to replace element in an array with its rank in the array
2+
#Rank in array will be the position of element in the sorted array
3+
def replacerank(num:list[int]):
4+
num2=sorted(num)
5+
for i in range(len(num)):
6+
for j in range(len(num2)):
7+
if num[i]==num[j]:
8+
num[i]==j+1#As the indexing starts from 0 but rank will start from 1
9+
return num
10+
print(replacerank([1,2,4,3]))
11+
12+
13+
14+
15+
16+
17+
18+

0 commit comments

Comments
 (0)