Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week2/day1 #42

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions POD/Week 2/day1_puja.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

def isomorphic(s,t):
if len(s)!=len(t):
return False
d1 = {}
d2 = {}
for i in range(len(s)):
if s[i] not in d1 and t[i] not in d2:
d1[s[i]] = t[i];
d2[t[i]] = s[i];
else:
if d1[s[i]] != t[i] or d2[t[i]] != s[i]:
return False
return True

print(isomorphic(input(),input()))
19 changes: 19 additions & 0 deletions POD/Week 2/day2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def isomorphic(s,t):
if len(s)!=len(t):
return False
#dictionaries to store 1-on-1 mappings
d1 = {}
d2 = {}
for i in range(len(s)):
#check if mapping between either s[i] or t[i] exists
if s[i] not in d1 and t[i] not in d2:
#create the mapping
d1[s[i]] = t[i];
d2[t[i]] = s[i];
else:
#check if the already existing mapping matches current one
if d1[s[i]] != t[i] or d2[t[i]] != s[i]:
return False
return True

print(isomorphic(input(),input()))
26 changes: 26 additions & 0 deletions POD/week1-arrays/day4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

for _ in range(int(input())):
n,s = map(int,input().split())
arr = list(map(int,input().split()))
#before start setting the indices of the subarray
i0,j0=-1,-1
for i in range(n):
#setting sum as the first element of the subarray
su = arr[i]
try:
#checking for an index j so that sum of arr[i:j] is the req sum
for j in range(i+1,n):
su += arr[j]
#if the sum is required sum set the indices of i and j
if su == s:
i0 = i
j0 = j
break

except:
pass
if j0!= -1:
print(i0+1,j0+1)
break
else:
print(-1)
19 changes: 19 additions & 0 deletions POD/week1-arrays/day5_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int,input().split()))
c = 0
#finding the bigger of the first and second element
p = max(l[:1])
for i in range(n):
#condition for record breaking:
#index 0: day 1 visitors is more than day 2
#day 2 to day n-1(day i): visitors is max of the subarray [0:i], and visitors on day i is more than i+1
#day n(last day) (index n-1):visitors is max of the full array
if (i == 0 or l[i] > p) and (i == n-1 or l[i]> l[i+1]):
c+=1
#updating the maximum no of visitors from the subarray[0:i]
if l[i]>p:
p = l[i]

print("Case #{}: {}".format(_+1,c))