Software Developer Mock Interview

Master 30 Software Developer interview questions covering algorithms, system design, and coding challenges.

Question 3 of 30

Tell me how you find duplicate numbers in an array in Java containing multiple duplicates?

  • How to Answer 1

  • How to Answer 2

  • Example Answer

  • Community Answers

Tom Dushaj
Tom Dushaj

Tom Dushaj is a business and technology executive and the author of 'Resumes That Work.' Tom has vast experience providing solutions to Fortune 500 companies in the areas of Information Technology Consulting, ERP Software, Personnel Management, and Intern

To find duplicate numbers with a given array of n2 elements with those elements in a range of 1 to n, I look for two numbers that occur twice to find the repeating numbers. An example would be an array {4, 2, 4, 5, 2, 3, 1} and n 5 to find the solution. Another example I can share is if an array has n 2 7 elements with elements occurring once except for 2 and 4, which occur twice. The output would then be 4 2. A simpler method that I have used is two loops. This works by picking elements one by one and counting the number of occurrences from the selected element in the inner loop. The benefit of this method is that you are using two repeating elements.

Unlock All 30 Software Developer Questions

Unlock expert responses to technical and behavioral questions interviewers ask developers.

Get Started