MockQuestions

Software Developer Mock Interview

Question 29 of 30 for our Software Developer Mock Interview

Software Developer was updated by on August 31st, 2021. Learn more here.

Question 29 of 30

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

"Problem solving has always been a strength of mine. I take them on to find a solution to a problem in the shortest time possible. In a recent project, I was working on a Java development project that required using Binary Search and Sorting. I started by adding a duplicate list of elements inserted back into an array. I also used two pointers to solve this, comparing an element and its closest neighbor to maintain a distinct element. Another method that I tried was by parsing all the items inside of an array containing 'n' to give me O(n). This way, we get an array of the n+1 element with integers between 1 and 4, which means there will be at least one duplicate as a result."

Next Question

How to Answer: Tell me how you find duplicate numbers in an array in Java containing multiple duplicates?

Advice and answer examples written specifically for a Software Developer job interview.

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

      How to Answer

      You will find that Java is used with many applications, on many different platforms, and a multitude of languages as well. If you're in software development and haven't learned to program in Java, I suggest you learn it as soon as possible. It is becoming a core technology for web development and development in general. It has many capabilities that other programming tools don't have, and that's why it's been a favorite for many developers. Everyone in IT has their own way of approaching a difficult problem and finding a solution. In this case, we're talking about finding duplicate numbers in an array in Java. Luckily Java is a go-to for most developers trying to solve this problem. An interviewer might phrase this question differently, but this is the easiest to understand. When you hear the words Sorted or Binary search, this means that they are looking for you to explain what inner and outer loops mean or parsing items inside an array. Be prepared for those questions as well.


      Written by Tom Dushaj on August 31st, 2021

      1st Answer Example

      "Problem solving has always been a strength of mine. I take them on to find a solution to a problem in the shortest time possible. In a recent project, I was working on a Java development project that required using Binary Search and Sorting. I started by adding a duplicate list of elements inserted back into an array. I also used two pointers to solve this, comparing an element and its closest neighbor to maintain a distinct element. Another method that I tried was by parsing all the items inside of an array containing 'n' to give me O(n). This way, we get an array of the n+1 element with integers between 1 and 4, which means there will be at least one duplicate as a result."

      Written by Tom Dushaj on August 31st, 2021

      2nd Answer Example

      "To find duplicate numbers with a given array of n+2 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."

      Written by Tom Dushaj on August 31st, 2021