From 04100dc874b34945a44ae4be5e5c53bc4e839bd9 Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:17:23 +0530 Subject: [PATCH 1/7] Create weekly 259 --- contests/Leetcode/weekly/weekly 259 | 1 + 1 file changed, 1 insertion(+) create mode 100644 contests/Leetcode/weekly/weekly 259 diff --git a/contests/Leetcode/weekly/weekly 259 b/contests/Leetcode/weekly/weekly 259 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259 @@ -0,0 +1 @@ + From 239b285e67cc68d042bec748443a7b84bcb1dd78 Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:17:58 +0530 Subject: [PATCH 2/7] Delete weekly 259 --- contests/Leetcode/weekly/weekly 259 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 contests/Leetcode/weekly/weekly 259 diff --git a/contests/Leetcode/weekly/weekly 259 b/contests/Leetcode/weekly/weekly 259 deleted file mode 100644 index 8b13789..0000000 --- a/contests/Leetcode/weekly/weekly 259 +++ /dev/null @@ -1 +0,0 @@ - From e0d703246f2e65ef5b35fe869b7347cd040d982d Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:20:04 +0530 Subject: [PATCH 3/7] Create weekly 259 --- contests/Leetcode/weekly/weekly 259 | 1 + 1 file changed, 1 insertion(+) create mode 100644 contests/Leetcode/weekly/weekly 259 diff --git a/contests/Leetcode/weekly/weekly 259 b/contests/Leetcode/weekly/weekly 259 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259 @@ -0,0 +1 @@ + From 0ad9d72f4472e411ce22a6fa1a2d0bad66a23d68 Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:26:12 +0530 Subject: [PATCH 4/7] Delete weekly 259 --- contests/Leetcode/weekly/weekly 259 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 contests/Leetcode/weekly/weekly 259 diff --git a/contests/Leetcode/weekly/weekly 259 b/contests/Leetcode/weekly/weekly 259 deleted file mode 100644 index 8b13789..0000000 --- a/contests/Leetcode/weekly/weekly 259 +++ /dev/null @@ -1 +0,0 @@ - From 6bd0725840c0da192ed55572a7c5d9de088ad2aa Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:27:19 +0530 Subject: [PATCH 5/7] Create hello.txt --- contests/Leetcode/weekly/weekly 259/hello.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 contests/Leetcode/weekly/weekly 259/hello.txt diff --git a/contests/Leetcode/weekly/weekly 259/hello.txt b/contests/Leetcode/weekly/weekly 259/hello.txt new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/hello.txt @@ -0,0 +1 @@ +hello From 362ee15a2fff9c3e510176bea70f938d085f6382 Mon Sep 17 00:00:00 2001 From: Ankan Mahapatra <69568975+ankan2526@users.noreply.github.com> Date: Fri, 1 Oct 2021 17:27:55 +0530 Subject: [PATCH 6/7] Add files via upload --- .../weekly/weekly 259/Detect Squares.py | 43 +++++++++++++++++++ ...of Variable After Performing Operations.py | 9 ++++ .../weekly 259/Sum of Beauty in the Array.py | 21 +++++++++ 3 files changed, 73 insertions(+) create mode 100644 contests/Leetcode/weekly/weekly 259/Detect Squares.py create mode 100644 contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py create mode 100644 contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py diff --git a/contests/Leetcode/weekly/weekly 259/Detect Squares.py b/contests/Leetcode/weekly/weekly 259/Detect Squares.py new file mode 100644 index 0000000..423916c --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Detect Squares.py @@ -0,0 +1,43 @@ +class DetectSquares: + + def __init__(self): + self.store={} + + def add(self, point: List[int]) -> None: + point=tuple(point) + if point not in self.store: + self.store[point]=0 + self.store[point]+=1 + + def count(self, point: List[int]) -> int: + ans=0 + x,y = point[0]-1,point[1]-1 + while x>=0 and y>=0: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x-=1 + y-=1 + x,y = point[0]-1,point[1]+1 + while x>=0 and y<=1000: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x-=1 + y+=1 + x,y = point[0]+1,point[1]-1 + while x<=1000 and y>=0: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x+=1 + y-=1 + x,y = point[0]+1,point[1]+1 + while x<=1000 and y<=1000: + if (x,y) in self.store and (x,point[1]) in self.store and (point[0],y) in self.store: + ans += self.store[(x,y)] * self.store[(x,point[1])] * self.store[(point[0],y)] + x+=1 + y+=1 + return ans + +# Your DetectSquares object will be instantiated and called as such: +# obj = DetectSquares() +# obj.add(point) +# param_2 = obj.count(point) diff --git a/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py b/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py new file mode 100644 index 0000000..2567f51 --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Final Value of Variable After Performing Operations.py @@ -0,0 +1,9 @@ +class Solution: + def finalValueAfterOperations(self, op: List[str]) -> int: + ans=0 + for i in op: + if '++' in i: + ans+=1 + else: + ans-=1 + return ans diff --git a/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py b/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py new file mode 100644 index 0000000..95d170c --- /dev/null +++ b/contests/Leetcode/weekly/weekly 259/Sum of Beauty in the Array.py @@ -0,0 +1,21 @@ +class Solution: + def sumOfBeauties(self, nums: List[int]) -> int: + n=len(nums) + ans=0 + for i in range(1,n-1): + if nums[i-1] Date: Fri, 1 Oct 2021 17:28:23 +0530 Subject: [PATCH 7/7] Delete hello.txt --- contests/Leetcode/weekly/weekly 259/hello.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 contests/Leetcode/weekly/weekly 259/hello.txt diff --git a/contests/Leetcode/weekly/weekly 259/hello.txt b/contests/Leetcode/weekly/weekly 259/hello.txt deleted file mode 100644 index ce01362..0000000 --- a/contests/Leetcode/weekly/weekly 259/hello.txt +++ /dev/null @@ -1 +0,0 @@ -hello