Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4403b83

Browse files
authored
Merge pull request fnplus#603 from prachijustin/my-new-feature
Matrix Rotation, kthSmallEle, StrRev
2 parents 5250b05 + 943cab0 commit 4403b83

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
''' Rotation of a Square matrix at 90 degree clockwise.
2+
With the least complexity
3+
'''
4+
l=[[1,2,3,4],
5+
[5,6,7,8],
6+
[9,10,11,12],
7+
[13,14,15,16]]
8+
9+
N = 4
10+
x=N-1
11+
y=x
12+
13+
#for square matrix
14+
for i in range(0, x):
15+
for j in range(i,x):
16+
l[j][x], l[i][j] = l[i][j], l[j][x]
17+
l[x][y], l[i][j] = l[i][j], l[x][y]
18+
l[y][i], l[i][j] = l[i][j], l[y][i]
19+
y -= 1
20+
x -= 1
21+
y=x
22+
23+
24+
25+
for i in l:
26+
print(i)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#Python program to find the kth smallest element from a list
2+
#Without doing sorting
3+
4+
5+
''' Eg: list is 61, 32, 80, 59, 20
6+
When sorted: 20, 32, 59, 61, 80
7+
3rd smallest element is: 59'''
8+
9+
N = int(input('Enter size of list: '))
10+
11+
print('Enter elements in list: ')
12+
l = [int(x) for x in input().split()]
13+
14+
K = int(input('kth element to search: '))
15+
x = max(l)+1
16+
ch = [0] *x
17+
18+
for j in range(0, N):
19+
ch[l[j]] += 1
20+
for j in range(0, len(ch)):
21+
if ch[j] >= 1:
22+
K -= 1
23+
if K == 0:
24+
print('Element is: ', j)
25+
break
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''
2+
Input: 'programming is fun'
3+
Output: 'fun is programming'
4+
'''
5+
#Method 1
6+
s = 'programming is fun'
7+
l = s.split()
8+
l.reverse()
9+
s = ' '.join(l)
10+
print(s)
11+
12+
13+
#Method 2
14+
s = 'programming is fun'
15+
s = s[::-1]
16+
ln=len(s)
17+
a=''
18+
for i in s:
19+
if i == ' ':
20+
x = a[::-1]
21+
s = s.replace(a,x)
22+
a = ''
23+
else:
24+
a += i
25+
26+
x=a[::-1]
27+
s=s.replace(a,x)
28+
print(s)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /