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

Day 5s POD by puja #37

Open
wants to merge 2 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
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))