Interview Questions

  • View all interview questions
  • blank
  • Find all duplicates in an array in linear time (v2)
    This is a common interview question where you need to write a program to find all duplicates in an array. The elements in the array have no restrictions, but in this algorithm we'll work specifically with integers. Finding duplicates in an array can be solved in linear time by using a hash table to store each element as we pass through the array. The general algorithm is:


    You need to be a premium member to see the rest of this question and code.

    Become a Premium Member

    With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

    “Daniel - Thanks so much for making Coderbyte! We still recommend it to people.” ― Shawn Drost
    • 200+ Coding Challenges
    • Mock Interview Questions
    • 500,000+ Code Solutions
    • Algorithm Tutorials
    • Interview Prep Courses
    mrdaniel published this on 11/11/15 | duplicate, array, search, Amazon, Facebook
    Comments
  • +
  • 1
  • -
  • Why do you use
     for i in range(0, len(arr)): 
    instead of
     for i in arr 
    - and reference i instead of arr[i] in the following code?
  • +
  • 0
  • -
  • @jaychiarella, Yes, in this case we can actually use the second line of code you posted because we are not doing anything in particular with the index i. Both lines of code you posted work, but maybe the second one is more readable and easier to understand :)
    Login to submit a comment