remove-duplicates-from-sorted-array: wrong result on empty list

Open Beginner friendly
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
devtools

Research direction

Open remove-duplicates-from-sorted-array/solution.py and inspect removeDuplicates, starting with its behavior when nums is empty. Add the empty-input handling described in the issue, then verify that an empty list returns 0 and existing sorted-list behavior is unchanged.

Written by the indexing model from the issue text.

Description

bug

removeDuplicates starts k=1 with no empty-list guard, so an empty input returns 1 instead of 0 — a latent bug masked by LeetCode's 1 <= nums.length constraint.

File: remove-duplicates-from-sorted-array/solution.py

Suggested fix: Add 'if not nums: return 0' guard.

Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from benthomasson/leetcode-implementations

All issues in benthomasson/leetcode-implementations

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.