Skip to content

Commit f43a838

Browse files
Add DSA problems
1 parent 8a0cfec commit f43a838

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

nonrepeatingchar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
s="siddhartha"
2+
temp=dict()
3+
for key in s:
4+
if key in temp:
5+
temp[key]+=1
6+
else:
7+
temp[key]=1
8+
for key in s:
9+
if temp[key]==1:
10+
print(key)
11+
12+

stockbuysell.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
arr=[100 ,180, 260, 310, 40, 535, 695]
2+
n=len(arr)
3+
aux=[0]*n
4+
aux[n-1]=arr[n-1]
5+
result=[[]]
6+
for i in range(n-2,-1,-1):
7+
aux[i]=max(aux[i+1],arr[i])
8+
print(aux)
9+
10+
max=0
11+
for i in range(n):
12+
if (aux[i]-arr[i])>max:
13+
result[0]=[arr[i],aux[i]]
14+
max=aux[i]-arr[i]
15+
elif (aux[i]-arr[i])==max:
16+
result.append([arr[i],aux[i]])
17+
18+
print(result)

0 commit comments

Comments
 (0)