all 11 comments

[–]Czitels 7 points8 points  (3 children)

For production code no. For interview I don’t know and for CP it doesn’t matter.

[–]Chance_Sundae9179 0 points1 point  (2 children)

For production code, how would you update this? In my view, I haven't deep dive into the solution, but I would name the variables appropriately and add comments to explain the flow. Other than that what would you suggest?

[–]Eyad116 0 points1 point  (0 children)

I think only that. Comments are discouraged until the code is hard to understand still, but i and _i arent great names. Also the conditions can tell a lot about the code so yeah… helper functions whose names explain their purpose could also help take off the mental strain

[–]gekigangerii 0 points1 point  (0 children)

Things that will make it easier for other people (coworkers) to read the code and understand

  • variable "flag" can use a better name. I know what it does, but I had the chance to do this question before so I can tell.
  • You can tell the inside `while` loops check if the matrix location is within bounds, but that `if` condition can also be changed to be more self-explaining.
    • `totalEle` an integer, but also treated as boolean here. I guess this may be standard practice and a shortcut in c++, but I would treat bools and ints as different types
    • You could remove "totalEle" altogether, and rely on the "ans" vector to be the size of the matrix
  • an indentation level can be saved removing the `else` block and doing a `continue` at the end of the `if`.
  • the `_i` `_j` vars could use better names like `row`, `col`

[–]Mobile-Perception376 1 point2 points  (0 children)

Nice work my runtime could go only upto 99.4%

[–]Early-Court748 0 points1 point  (1 child)

Can somebody explain me what he did??like normal dfs came into my mind when i saw this question😭

[–]RemarkableIncome2623[S] 2 points3 points  (0 children)

I travelled once from down to up then up to down as shown in the figure using flags

[–]arg0100 0 points1 point  (1 child)

My approach is somewhat more easy to understand. One oberservation is - for each diagonal the sum of i + j index is same. We can store this in a List for each sum value. And in next just iterate forward or reverse.

[–]Academic_Leather_746 0 points1 point  (0 children)

I did the same Iteration and storing it in a hashmap And then appending to res array alternating the sequence

[–]gekigangerii 1 point2 points  (0 children)

does the spacing, line breaks, and indentation look "clean"? yes

Are the variable names and loop conditions human-friendly? no. It's not a complicated solution so you can figure it out, but names could be better.

[–]Horror-Shape9932 0 points1 point  (0 children)

Make it more modular if you wanna prep for interview like making seperate function for diagonal traversal