Skip to content

adding backtracking-1 soln#1141

Open
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master
Open

adding backtracking-1 soln#1141
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master

Conversation

@nikhylw
Copy link
Copy Markdown

@nikhylw nikhylw commented May 17, 2026

Solution 1 (Combination Sum) - W6_combination_sum.py

@super30admin
Copy link
Copy Markdown
Owner

Combination Sum (W6_combination_sum.py)

Strengths:

  1. Correctly implements backtracking with proper state restoration using path.pop()
  2. More memory efficient than the reference solution by reusing a single path list instead of creating copies
  3. Clean, readable code structure with clear comments
  4. Proper use of list(path) when adding to results to capture the current state

Areas for Improvement:

  1. The time complexity comment is slightly optimistic - the actual complexity is higher due to exploring all combinations
  2. The space complexity comment is incorrect - it should account for the recursion depth which can be up to target/min_candidate
  3. The comments about "Deep copy path list" are inaccurate since no deep copies are being made in the recursive calls
  4. Consider adding type hints for better code documentation (e.g., candidates: List[int], target: int)

VERDICT: PASS


Operations and expressions

The student has submitted a solution for the wrong problem. The submitted code solves "Combination Sum" (LeetCode 39) where you find combinations of numbers from a candidates array that sum to a target, but the actual problem is "Expression Add Operators" where you insert operators (+, -, *) between digits of a string.

For the correct problem, the solution needs to:

  • Handle string input and parse substrings as numbers
  • Insert operators between digits (not choose/reuse elements)
  • Handle operator precedence (multiplication before addition/subtraction)
  • Track both the calculated value and the "tail" value for proper multiplication handling
  • Ensure no leading zeros in operands

The student should carefully read the problem statement and ensure their solution addresses the specific requirements before submitting.

VERDICT: NEEDS_IMPROVEMENT

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