Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment_1 #1

Merged
merged 1 commit into from
Mar 4, 2025
Merged

assignment_1 #1

merged 1 commit into from
Mar 4, 2025

Conversation

k2jac9
Copy link
Owner

@k2jac9 k2jac9 commented Feb 17, 2025

What changes are you trying to make?

🔄 Changes Implemented

  • Refactoring the code for the "Missing Number in Range" problem to handle edge cases correctly. This includes using the maximum value from the list (instead of its length) to determine the full range of numbers and correctly account for repeated numbers.

What did you learn from the changes you have made?

📚 Key Learnings

  • Relying on len(nums) can lead to incorrect results when the missing numbers lie beyond the list length.
  • Using max(nums) ensures that the complete expected range of numbers is considered.
  • Different approaches (set difference vs. boolean array) have their own trade-offs in terms of readability and space usage.

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

🔍 Alternative Approaches Considered

  • One alternative was using a boolean (or frequency) array to mark the presence of numbers, then iterating over it to identify which indices (numbers) were not marked.
  • Another approach considered was modifying the list in-place using negation to mark visited numbers, but that approach struggled with cases where the expected range extends beyond the list length.

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

🚧 Challenges & Solutions

  • A key challenge was handling cases like [0, 1] and [0] where the missing number is at the end of the expected range. Initially, the code only checked up to len(nums), which was insufficient.
  • This was overcome by adjusting the logic to use max(nums) to determine the upper bound of the range, ensuring that all possible missing numbers are considered.

How were these changes tested?

🧪 Testing Methodology

  • The code was tested with multiple cases, including:
    • [0, 2] should return [1].
    • [5, 0, 1] should return [2, 3, 4].
    • [0, 1] should return -1 (no missing numbers).
    • [0] should return [1].
  • The outputs from these test cases were printed and verified against expected results.

A reference to a related issue in your repository (if applicable)

🔗 N/A

Checklist ✅

  • I can confirm that my changes are working as intended

@k2jac9 k2jac9 merged commit b7028d8 into main Mar 4, 2025
1 check passed
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