From 0fd63084f09c28e5298ba99899350195b9de83cd Mon Sep 17 00:00:00 2001 From: pujab21 <94778475+pujab21@users.noreply.github.com> Date: Tue, 31 May 2022 19:47:23 +0530 Subject: [PATCH 1/3] Day 5s POD by puja --- POD/week1-arrays/day5_2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 POD/week1-arrays/day5_2.py 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)) From 1de001949596e110502a0a00f62942a0f358f662 Mon Sep 17 00:00:00 2001 From: pujab21 <94778475+pujab21@users.noreply.github.com> Date: Tue, 31 May 2022 19:58:45 +0530 Subject: [PATCH 2/3] Create day4.py --- POD/week1-arrays/day4.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 POD/week1-arrays/day4.py 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) From 8e4b10414c05c9b20e43d1737f925a1d80973862 Mon Sep 17 00:00:00 2001 From: pujab21 <94778475+pujab21@users.noreply.github.com> Date: Wed, 1 Jun 2022 20:48:07 +0530 Subject: [PATCH 3/3] Create day3.py --- POD/week2/day3.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 POD/week2/day3.py diff --git a/POD/week2/day3.py b/POD/week2/day3.py new file mode 100644 index 0000000..eca2520 --- /dev/null +++ b/POD/week2/day3.py @@ -0,0 +1,23 @@ +class Solution(object): + def minimumSwap(self, s1, s2): + x,y = 0,0 + swaps = 0 + for i in range(len(s1)): + #ignore all the x and y which are equal + if s1[i]!=s2[i]: + if s1[i]=="x": + x+=1 + else: + y+=1 + + #if the total number of x and y we need to swap is odd, we cant swap to form 2 equak strings + if ((x+y)%2 ==1): + return -1 + else: + #we can group each to be swapped into pairs of xx or yy + #then it will be xx(s1) and yy(s2) or vice versa which requires 1 swap + #so for total xx(s1) and yy(s2) pairs we can get it as x//2 + x//y + #the remaining will be odd number of x(s1) and y(s2) or vice versa which requires 1 swap + #so for total xy and yx it is x%2(reminder when x//2) + y%2(reminder when y//2) + + return y//2+y%2+x//2+x%2