Skip to content

Completed Arrays 2#1880

Open
sanjoli97 wants to merge 1 commit into
super30admin:masterfrom
sanjoli97:master
Open

Completed Arrays 2#1880
sanjoli97 wants to merge 1 commit into
super30admin:masterfrom
sanjoli97:master

Conversation

@sanjoli97

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Disappeared Numbers (FindDisappearedNumbers.java)

Strengths:

  • Correctly implements the O(n) time, O(1) space solution using in-place array modification
  • Clean, readable code with good variable names
  • Excellent time complexity (O(n)) compared to the reference solution's O(n²)
  • Good use of comments explaining the approach
  • Properly handles edge cases like duplicate values

Areas for Improvement:

  • The comment "TC - O(n)" is slightly imprecise; technically this is O(2n) = O(n), but the first pass is O(n) and second pass is O(n), so overall O(n)
  • Could add a brief comment explaining why we use Math.abs() - to handle cases where we've already negated the value

Comparison to Reference:

  • The student's solution is significantly more efficient (O(n) vs O(n²))
  • The student achieves the follow-up requirement that the reference solution does not

VERDICT: PASS


max and min (MinAndMax.java)

Strengths:

  • Correctly implements the optimal pairwise comparison algorithm
  • Excellent comment explaining time complexity O(3n/2)
  • Clean, readable code with good variable naming
  • Properly handles edge cases (odd/even array lengths)
  • Well-documented logic flow

Areas for Improvement:

  • Consider returning int[] instead of ArrayList<Integer> for better performance (avoids autoboxing and wrapper object creation)
  • The while condition i < arr.length - 1 works but could be simplified to i < arr.length since the pair comparison naturally stops at the last valid pair
  • Could add a null check for robustness in production code

VERDICT: PASS


Life Game (GameOfLife.java)

Strengths:

  • Good use of in-place modification technique with marker values
  • Clear separation between logic and cleanup phases
  • Well-documented with explanatory comments
  • Proper boundary checking in the counting method

Areas for Improvement:

  • Critical Bug: The condition board[nr][nc] > 0 in countLiveCells is incorrect. It counts cells with value 2 as live, but these are actually dead cells (1→0 transitions). Should use board[nr][nc] == 1 || board[nr][nc] == 2 like the reference solution.
  • Incorrect Time Complexity Comment: The comment states O(n) but should be O(m*n) for a 2D grid.
  • Edge Case: When count is exactly 3, the code correctly handles birth for dead cells and survival for live cells. However, the counting bug could cause cascading errors in complex configurations.

VERDICT: NEEDS_IMPROVEMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants