Skip to content

Solution Arry-2#1865

Open
shakthinandana wants to merge 4 commits intosuper30admin:masterfrom
shakthinandana:master
Open

Solution Arry-2#1865
shakthinandana wants to merge 4 commits intosuper30admin:masterfrom
shakthinandana:master

Conversation

@shakthinandana
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Disappeared Numbers (findminmax.py)

It appears you have submitted a solution for a different problem (finding min and max) instead of the "Disappeared Numbers" problem. Please ensure you are solving the correct problem. For the min-max problem, your code is correct and efficient. However, for the disappeared numbers problem, you need to implement a solution that finds missing numbers in the range [1, n]. Consider using techniques like marking indices as visited by negating values or using a set for O(n) time complexity.

VERDICT: NEEDS_IMPROVEMENT


max and min (findmissing.py)

It seems there might be a misunderstanding. The problem you were asked to solve is to find the minimum and maximum in an array with a constraint on the number of comparisons (less than 2*(N-2)). However, your solution is for a different problem: finding disappeared numbers in an array.

For the min-max problem, you need to compare elements to find the smallest and largest. The reference solution uses a technique that processes elements in pairs to reduce the number of comparisons. For each pair, it first compares the two elements to each other (1 comparison), and then compares the smaller to the current min (1 comparison) and the larger to the current max (1 comparison). This leads to about 3 comparisons per 2 elements, which is better than the naive approach of 2 comparisons per element (which would be 2*(N-1) comparisons).

I recommend reviewing the problem statement again and implementing the min-max solution. You can start by handling the array length (even or odd) and then processing pairs. For each pair, compare the two elements to determine the local min and max, then update the global min and max. This way, you use approximately 3*(n/2) comparisons, which is less than 2*(n-2) for n>=2.

VERDICT: NEEDS_IMPROVEMENT


Life Game (gameOfLife.py)

Your solution is correct and efficient. Well done! You successfully implemented the in-place update with O(1) space and O(m*n) time. Here are a few suggestions for improvement:

  1. Remove the unused variable res = board as it serves no purpose.
  2. Consider using more descriptive variable names. For example, surround could be renamed to directions or neighbors_directions.
  3. The use of absolute value to check for live cells is clever, but it might be slightly less intuitive than using specific markers (like 2 and 3). However, your approach is valid.
  4. Ensure that your code is well-commented to explain the meaning of the markers (e.g., what does -1 represent? what does 2 represent?). This will make the code easier to understand for others.

Overall, your solution is good. Keep up the good work!

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