Skip to content

Bug Report for find-duplicate-integer #5940

Description

@elizacohen5

Bug Report for https://neetcode.io/problems/find-duplicate-integer

I you enter the following solution to find-duplicate-integer, you will notice that the values for the 2 pointers reported in the description of the step do not match with the graphic visualization. The graphics show the wrong value for the pointers throughout the problem.

class Solution:
def findDuplicate(self, nums: List[int]) -> int:
# Phase 1: find an intersection point inside the cycle
slow = nums[0]
fast = nums[0]
while True:
slow = nums[slow] # one step
fast = nums[nums[fast]] # two steps
if slow == fast:
break
# Phase 2: find the entrance to the cycle (the duplicate)
slow = nums[0]
while slow != fast:
slow = nums[slow]
fast = nums[fast]
return slow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions