diff --git a/POD/week1-arrays/day4.py b/POD/week1-arrays/day4.py new file mode 100644 index 0000000..ab5c6f4 --- /dev/null +++ b/POD/week1-arrays/day4.py @@ -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) diff --git a/POD/week1-arrays/day5_2.py b/POD/week1-arrays/day5_2.py new file mode 100644 index 0000000..2a02240 --- /dev/null +++ b/POD/week1-arrays/day5_2.py @@ -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))