-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3af93a
commit 98e92bd
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
arr=['hello','world','hell'] | ||
minword=min(arr) | ||
print(minword) | ||
prefix="" | ||
for i in arr: | ||
temp="" | ||
for j in range(len(minword)): | ||
if i[j] == minword[j]: | ||
temp+=minword[j] | ||
if prefix=="": | ||
prefix=temp | ||
if len(prefix)>len(temp): | ||
prefix=temp | ||
|
||
flag=1 | ||
for i in arr: | ||
if prefix[0] != i[0]: | ||
flag=0 | ||
break | ||
|
||
if flag==1: | ||
print(prefix) | ||
else: | ||
print("no common element") | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
arr=[1,3,2,4] | ||
n=len(arr) | ||
stack=[] | ||
result=[0]*n | ||
for i in range(n-1,-1,-1): | ||
while stack and stack[-1]<=arr[i]: | ||
stack.pop() | ||
if stack: | ||
result[i]=stack[-1] | ||
stack.append(arr[i]) | ||
|
||
for i in range(n): | ||
if result[i]==0: | ||
result[i]=-1 | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
s1="siddhartha" | ||
s2='siddhantha' | ||
temp=[] | ||
for i in s1: | ||
if i not in temp: | ||
temp.append(i) | ||
|
||
print(temp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
arr=[3,1,2,4,0,1,3,2] | ||
n=len(arr) | ||
left=[] | ||
right=[0]*n | ||
left.append(arr[0]) | ||
for i in range(1,n): | ||
left.append(max(arr[i],left[i-1])) | ||
|
||
print(left) | ||
right[n-1]=arr[n-1] | ||
for i in range(n-2,-1,-1): | ||
right[i]=max(right[i+1],arr[i]) | ||
|
||
|
||
total=0 | ||
for i in range(0,n): | ||
total=total+(min(left[i],right[i])-arr[i]) | ||
print(total) |