From 7db56ee7c377dc46881f6657fd09c54069514e18 Mon Sep 17 00:00:00 2001 From: Bharath Vuppala Date: Tue, 14 Jan 2025 13:16:08 -0800 Subject: [PATCH 1/2] 3 problems completed --- Diagnol Traverse.py | 49 +++++++++++++++++++++++++++++++ Product of array except itself.py | 18 ++++++++++++ Spiral Matrix.py | 41 ++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 Diagnol Traverse.py create mode 100644 Product of array except itself.py create mode 100644 Spiral Matrix.py diff --git a/Diagnol Traverse.py b/Diagnol Traverse.py new file mode 100644 index 00000000..3ce41c25 --- /dev/null +++ b/Diagnol Traverse.py @@ -0,0 +1,49 @@ +#Time complexity - 0(m*n) & space complexity - o(1) +class Solution: + def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]: + if mat== None or len(mat)==0: + return [] + + m= len(mat) + n= len(mat[0]) + result= [ 0 for i in range(m*n)] + + index =0 + r=0 + c=0 + dirr=1 + while index List[int]: + + if nums == None or len(nums)==0: + return [] + n= len(nums) + rp=1 + result=[0 for i in range(n)] + result[0]=1 + for i in range (1, n): + rp = rp * nums[i-1] + result[i]=rp + rp =1 + for i in range (n-2, -1, -1): + rp = rp * nums[i+1] + result[i] = result[i]* rp + return result \ No newline at end of file diff --git a/Spiral Matrix.py b/Spiral Matrix.py new file mode 100644 index 00000000..1701537b --- /dev/null +++ b/Spiral Matrix.py @@ -0,0 +1,41 @@ +#Time complexity - 0(m*n) & space complexity - o(1) +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + if matrix == None or len(matrix) ==0: + return [] + m= len(matrix) + n= len(matrix[0]) + result=[] + top=0 + bottom= m-1 + left =0 + right =n-1 + + while top<=bottom and left<=right: + if top<=bottom and left<=right: + for i in range(left, right+1): + result.append(matrix[top][i]) + top = top+1 + if top<=bottom and left<=right: + for i in range(top , bottom+1): + result.append(matrix[i][right]) + right = right-1 + if top<=bottom and left<=right: + for i in range(right, left-1,-1): + result.append(matrix[bottom][i]) + bottom = bottom-1 + if top<=bottom and left<=right: + for i in range(bottom, top-1,-1): + result.append(matrix[i][left]) + left=left+1 + + + return result + + + + + + + + \ No newline at end of file From 8d611a4801a3c198683dc8e4c540d301b425cb1a Mon Sep 17 00:00:00 2001 From: BharathVuppala96 Date: Wed, 7 Jan 2026 12:33:27 -0800 Subject: [PATCH 2/2] 3problems completed --- Diagnol Traverse.py | 45 +++++++++++-------------------- Product of array except itself.py | 20 +++++++------- Spiral Matrix.py | 12 ++------- 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/Diagnol Traverse.py b/Diagnol Traverse.py index 3ce41c25..322b0e3e 100644 --- a/Diagnol Traverse.py +++ b/Diagnol Traverse.py @@ -1,49 +1,36 @@ -#Time complexity - 0(m*n) & space complexity - o(1) class Solution: def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]: - if mat== None or len(mat)==0: - return [] + m=len(mat) + n=len(mat[0]) - m= len(mat) - n= len(mat[0]) - result= [ 0 for i in range(m*n)] - - index =0 + result=[0 for i in range(m*n)] + + index=0 r=0 c=0 dirr=1 + while index List[int]: + n=len(nums) - if nums == None or len(nums)==0: - return [] - n= len(nums) - rp=1 result=[0 for i in range(n)] result[0]=1 - for i in range (1, n): - rp = rp * nums[i-1] + rp=1 + for i in range(1,n): + rp=rp*nums[i-1] result[i]=rp - rp =1 - for i in range (n-2, -1, -1): - rp = rp * nums[i+1] - result[i] = result[i]* rp + print(result) + rp=1 + for i in range(n-2,-1,-1): + rp=rp*nums[i+1] + result[i]=rp*result[i] return result \ No newline at end of file diff --git a/Spiral Matrix.py b/Spiral Matrix.py index 1701537b..4fd78306 100644 --- a/Spiral Matrix.py +++ b/Spiral Matrix.py @@ -1,4 +1,4 @@ -#Time complexity - 0(m*n) & space complexity - o(1) + class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: if matrix == None or len(matrix) ==0: @@ -30,12 +30,4 @@ def spiralOrder(self, matrix: List[List[int]]) -> List[int]: left=left+1 - return result - - - - - - - - \ No newline at end of file + return result \ No newline at end of file