Find duplicate in an array of N+1 Integers in Python

prepinsta-prime

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

3 comments on “Find duplicate in an array of N+1 Integers in Python”


  • nandan767644

    def find_duplicate(nums):
    nums.sort()
    for i in range(1, len(nums)):
    if nums[i] == nums[i – 1]:
    return nums[i]


  • nandan767644

    def find_duplicate(nums):
    seen = set()
    for num in nums:
    if num in seen:
    return num
    seen.add(num)
    nums=[1,2,3,4,2,2]
    print(find_duplicate(nums))


  • nitesh

    a=[-1, 8, 1, 8, -1, 5, 1, -3]
    a.sort()
    d=[]
    s=[]
    for i in a:
    if i not in d:
    d.append(i)
    else:
    s.append(i)
    print(s)