Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done arr 1 #1643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions diag_ele_matrix_498.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#O(mn) sc o(min(m,n))
class Solution:
def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:
q = deque([(0, 0)])
rows, cols = len(mat), len(mat[0])
ans = []
reverse = False

while q:
level = []
for _ in range(len(q)):
row, col = q.popleft()
level.append(mat[row][col])

if col == 0 and row + 1 < rows:
q.append((row + 1, col))
if col + 1 < cols:
q.append((row, col + 1))

if reverse:
ans.extend(level[::-1])
else:
ans.extend(level)
reverse = not reverse

return ans
17 changes: 17 additions & 0 deletions product_except_self_238.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
n = len(nums)
res = [1] * n
prefix_prod = 1
suffix_prod = 1

for i in range(n):
res[i] = res[i] * prefix_prod
prefix_prod = prefix_prod * nums[i]

for i in range(n - 1, -1, -1):
res[i] = res[i] * suffix_prod
suffix_prod = suffix_prod * nums[i]
return res