You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interview Problem: Find Missing Number in a sorted array (Problem1.py)
Strengths:
Your solution uses binary search effectively, achieving O(log n) time complexity.
The logic of comparing ar[mid] - mid with the reference value is a clever approach.
The code is concise and readable.
Areas for Improvement:
Edge Case Handling: Your solution fails when the missing number is the last element in the sequence (e.g., [1, 2, 3, 4, 5, 6, 7] where 8 is missing). In this case, a remains -1 and ar[-1] + 1 gives incorrect results. You should handle this case by returning len(ar) + 1 or similar when a == -1.
Import Statement: You're using List[int] but haven't imported it. Add from typing import List at the top.
Variable Naming: The variable a is not descriptive. Consider renaming it to something like last_valid_index or breakpoint.
Documentation: Add a docstring explaining the approach and edge cases handled.
VERDICT: NEEDS_IMPROVEMENT
Interview Problem: Design Min Heap (Problem2.py)
Correctness: Your solution correctly implements all the required operations (insert, removeMin, printHeap) and matches the reference solution's logic. The translation from C++ to Python is accurate.
Time/Space Complexity: Both complexities match the reference solution - O(log n) for insert/remove and O(n) for space.
Code Quality: The code is well-structured, readable, and follows Python best practices. Good use of comments documenting the complexities.
Minor Improvement: Consider adding input validation or error handling for edge cases (e.g., what happens when trying to insert into a full heap - currently it silently returns without notifying the user).
Pythonic Improvements: You could use Python's heapq module for comparison, but implementing it from scratch (as you did) is excellent for understanding the data structure.
VERDICT: PASS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.