Skip to content

Complete Competitive-Coding-1 - #1362

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

Complete Competitive-Coding-1#1362
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

Interview Problem: Find Missing Number in a sorted array (Problem1.py)

Strengths:

  1. Your solution uses binary search effectively, achieving O(log n) time complexity.
  2. The logic of comparing ar[mid] - mid with the reference value is a clever approach.
  3. The code is concise and readable.

Areas for Improvement:

  1. 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.

  2. Import Statement: You're using List[int] but haven't imported it. Add from typing import List at the top.

  3. Variable Naming: The variable a is not descriptive. Consider renaming it to something like last_valid_index or breakpoint.

  4. Documentation: Add a docstring explaining the approach and edge cases handled.

VERDICT: NEEDS_IMPROVEMENT


Interview Problem: Design Min Heap (Problem2.py)

  1. 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.

  2. Time/Space Complexity: Both complexities match the reference solution - O(log n) for insert/remove and O(n) for space.

  3. Code Quality: The code is well-structured, readable, and follows Python best practices. Good use of comments documenting the complexities.

  4. 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).

  5. 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

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