Skip to content

Complete Array-2 Assignment - #1889

Open
tejbharath wants to merge 2 commits into
super30admin:masterfrom
tejbharath:master
Open

Complete Array-2 Assignment#1889
tejbharath wants to merge 2 commits into
super30admin:masterfrom
tejbharath:master

Conversation

@tejbharath

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Find All Numbers Disappeared in an Array (DisappearedNumbers.java)

Your solution is excellent! You've chosen the optimal algorithm for this problem - the negative marking technique achieves both O(n) time complexity and O(1) space complexity, which perfectly satisfies the follow-up requirements. Your code is clean, well-documented, and correctly handles edge cases like duplicate values. The only minor suggestions would be to use more descriptive variable names and to follow LeetCode's naming conventions (typically Solution for the class name). Great work overall!

VERDICT: PASS


max and min (MaxAndMinArray.java)

Strengths:

  1. Correct logic for finding min and max
  2. Good defensive programming with input validation
  3. Clear comments explaining the approach
  4. O(n) time complexity and O(1) space complexity
  5. Well-structured code

Areas for Improvement:

  1. Comparison Count: The solution doesn't meet the optimization requirement of less than 2*(N-2) comparisons. Your approach uses approximately 3*(n-1) comparisons (1 for if-else + 1 for Math.max + 1 for Math.min per iteration), which exceeds the target.
  2. Method Naming: Follow Java naming conventions - use camelCase like findMaxAndMin instead of PascalCase.
  3. Optimization Opportunity: Consider the pair-based approach where you first compare elements within pairs to determine local min/max, then compare these with global min/max. This reduces comparisons to approximately 3n/2.

VERDICT: NEEDS_IMPROVEMENT


Game of Life (GameOfLife.java)

Strengths:

  1. Your solution correctly implements the Game of Life rules using an in-place approach.
  2. Good use of comments to explain the encoding strategy (-1 for live-to-die, 2 for die-to-live).
  3. The code is well-organized with a separate helper method for counting neighbors.
  4. Time and space complexity match the optimal solution.

Areas for Improvement:

  1. Avoid redundant function calls: In the line if(livingCount(board, i, j) < 2 || livingCount(board, i, j) > 3), you're calling livingCount twice. Store the result in a variable to avoid this:
    int count = livingCount(board, i, j);
    if(count < 2 || count > 3) {
        board[i][j] = -1;
    }
  2. Consider making dirs a constant: Since the directions never change, you could declare it as private static final int[][] DIRS to make it clear it's a constant.
  3. Minor style note: The dirs array is declared as an instance variable but doesn't depend on instance state. Making it static would be cleaner.

Overall, your solution is correct and efficient. The main improvement is just avoiding the redundant function call.

VERDICT: PASS

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