diff --git a/Problem_1.1.py b/Problem_1.1.py new file mode 100644 index 00000000..b7fa3cdc --- /dev/null +++ b/Problem_1.1.py @@ -0,0 +1,20 @@ +# // Time Complexity : O(n) +# // Space Complexity : O(1) + +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + prod = nums[0] + output = [i for i in nums] + + for i in range(1,len(nums)): + output[i] = prod + prod *= nums[i] + + + prod = nums[-1] + output[0] = 1 + for i in range(len(nums)-2, -1, -1): + output[i] = output[i] * prod + prod *= nums[i] + + return(output) \ No newline at end of file diff --git a/Problem_1.2.py b/Problem_1.2.py new file mode 100644 index 00000000..11a038eb --- /dev/null +++ b/Problem_1.2.py @@ -0,0 +1,34 @@ +# // Time Complexity : O(n*m) +# // Space Complexity : O(1) +class Solution: + def findDiagonalOrder(self, matrix: List[List[int]]) -> List[int]: + + upFlag = 1 + m = len(matrix) + n = len(matrix[0]) + i,j = 0,0 + result = [] + while(i List[int]: + + min_n,max_n,min_m,max_m = 0,len(matrix),0,len(matrix[0]) + + output = [] + + while (min_n < max_n and min_m < max_m): + + for j in range(min_m,max_m): + output.append(matrix[min_n][j]) + min_n += 1 + + for i in range(min_n,max_n): + output.append(matrix[i][max_m-1]) + max_m -= 1 + + if min_n < max_n: + for j in range(max_m-1,min_m-1,-1): + output.append(matrix[max_n-1][j]) + max_n -= 1 + if min_m < max_m: + for i in range(max_n-1,min_n-1,-1): + output.append(matrix[i][min_m]) + min_m += 1 + + return(output) \ No newline at end of file