Skip to content

Complete Array-2 - #1893

Open
satish-paraddi wants to merge 2 commits into
super30admin:masterfrom
satish-paraddi:master
Open

Complete Array-2#1893
satish-paraddi wants to merge 2 commits into
super30admin:masterfrom
satish-paraddi:master

Conversation

@satish-paraddi

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Find All Numbers Disappeared in an Array (Problem_1.py)

Excellent work! Your solution demonstrates a strong understanding of the problem and implements an optimal algorithm. Here are some specific points:

Strengths:

  • You correctly identified and implemented the in-place negation technique, which is the standard optimal solution
  • Your time complexity of O(n) is optimal and meets the follow-up requirement
  • Your space complexity of O(1) is optimal
  • The code is clean, readable, and well-commented
  • Good use of abs() to handle previously negated values

Suggestions for further improvement:

  • Consider adding inline comments to explain the algorithm's logic (e.g., why we use abs(nums[i]) - 1 and why we check nums[j] > 0)
  • You could add a brief docstring explaining the approach for future reference
  • Consider edge cases in your testing: empty array, array with all unique numbers, array with all duplicates

Comparison with reference: Your solution is significantly better than the reference solution in terms of time complexity (O(n) vs O(n²)) while maintaining the same space complexity. The reference solution would actually receive a Time Limit Exceeded on LeetCode for large inputs.

VERDICT: PASS


max and min (Problem_2.py)

It appears you have submitted a solution for the "Game of Life" problem instead of the "max and min" problem. These are completely different problems:

  • Game of Life: Simulates cellular automaton rules on a 2D board
  • Max and Min: Find the minimum and maximum values in an array using fewer than 2*(N-2) comparisons

To solve the actual problem, you need to:

  1. Take an array of numbers as input
  2. Find both the minimum and maximum values
  3. Use fewer than 2*(N-2) comparisons (the optimal approach uses about 1.5*(N-2) comparisons by processing elements in pairs)

A correct approach would be:

  • Compare pairs of elements first (1 comparison per pair)
  • Then compare the smaller with current min and larger with current max (2 more comparisons per pair)
  • This gives 3 comparisons per 2 elements = 1.5*(N-2) comparisons total

Please resubmit with the correct solution for the max and min problem.

VERDICT: NEEDS_IMPROVEMENT


Game of Life

Excellent work! Your solution for the Game of Life problem is correct, efficient, and well-implemented. Here are some specific points:

Strengths:

  • Your solution correctly implements the in-place encoding technique using values 2 and 3 as intermediate states
  • The two-pass approach correctly handles the simultaneous update requirement
  • The code is clean, readable, and follows Python conventions
  • Time and space complexity match the optimal solution

Minor suggestions for improvement:

  • Consider adding a brief comment explaining what values 2 and 3 represent (e.g., # 2: live->dead, 3: dead->live) to improve code documentation
  • The getCount function could be slightly optimized by inlining the direction checks, but this is a minor stylistic choice
  • Consider adding edge case handling documentation in comments

Overall: Your solution demonstrates a strong understanding of the problem and the optimal in-place approach. The implementation is essentially identical to the reference solution in terms of algorithm and efficiency.

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