Skip to content

Array-2#1870

Open
hiteshmadapathi wants to merge 9 commits intosuper30admin:masterfrom
hiteshmadapathi:Summer-2026
Open

Array-2#1870
hiteshmadapathi wants to merge 9 commits intosuper30admin:masterfrom
hiteshmadapathi:Summer-2026

Conversation

@hiteshmadapathi
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Disappeared Numbers (Find Disappeared Number.py)

Your solution is excellent! It correctly solves the problem with optimal time and space complexity. Here are some points to consider:

Strengths:

  • You used the in-place marking technique effectively, which is a common pattern for such problems.
  • The code is clean and well-commented.
  • You handled the index mapping correctly (using abs(nums[i])-1 to get the index).

Areas for improvement:

  1. Although restoring the original array is not necessary, it is a good practice if we want to avoid side effects. However, in competitive programming, it is often acceptable to modify the input. You can skip this step to save a little time, but it's not a big issue.
  2. The variable name re for result is a bit short. Using result or res would be more conventional and readable.
  3. You might add a brief comment explaining the marking process for clarity.

For example:

# Mark each number that appears by negating the value at its corresponding index
for i in range(n):
    index = abs(nums[i]) - 1
    if nums[index] > 0:
        nums[index] *= -1

# Collect indices where the value is positive (which means the number was not found)
result = []
for i in range(n):
    if nums[i] > 0:
        result.append(i+1)
    # Optional: restore the original value
    # nums[i] = abs(nums[i])

Overall, great job!

VERDICT: PASS


max and min (GameOfLife.py)

Dear student,

It appears you have submitted your solution to the wrong problem. The reference solution provided is for finding the minimum and maximum values in an array, but your code is for Conway's Game of Life. Please make sure you're working on the correct problem.

Regarding your Game of Life implementation:

  1. Your approach to use transitional states (2 and 3) is a good idea for in-place updates, but the implementation needs refinement.
  2. The neighbor counting function helper doesn't correctly identify live neighbors during the transitional phase. When counting neighbors, you should check if a cell is currently alive (value 1) OR in state 2 (which means it was alive but will die), as both represent currently live cells.
  3. You're modifying the board while counting neighbors, which will lead to incorrect results since the neighbor counts will be affected by the transitional states.
  4. Consider separating the neighbor counting from the board modification. You might want to:
    • First, create a copy of the board or use a separate array to count neighbors
    • Alternatively, use the transitional states properly by checking both original live states (1) and transitional states that represent currently live cells (2)

For the Game of Life problem, a better approach would be:

  1. First, iterate through each cell and count live neighbors (considering both 1 and 2 as "currently alive")
  2. Then, apply the rules and mark cells with transitional states
  3. Finally, update the board to convert transitional states to their final values

VERDICT: NEEDS_IMPROVEMENT


Life Game (Problem2.py)

It seems there has been a misunderstanding. The problem you were asked to solve is Conway's Game of Life, which involves updating a 2D grid based on the number of live neighbors each cell has. However, your solution is for a completely different problem (finding the minimum and maximum in a 1D array).

Please review the problem statement again. You need to write a function that takes a 2D list board and updates it in-place according to the rules of the Game of Life. The key points are:

  • You must update the board simultaneously, meaning you cannot update cells one by one without storing the next state.
  • You should consider using an intermediate state representation (like the reference solution does) to avoid overwriting values that are needed for other calculations.

I recommend:

  1. Understanding the problem rules thoroughly.
  2. Using the reference solution as a guide (but note it is in Java, so you'll need to adapt to Python).
  3. Implementing a solution that counts live neighbors for each cell and then applies the rules.

For example, in Python, you might:

  • Create a copy of the board to store the next state, OR
  • Use intermediate states (like 2 for "was alive but will die" and 3 for "was dead but will become alive") to update in-place without extra space.

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