20+ Array Coding Problems and Questions from Programming Interviews

javinpaul
Javarevisited
Published in
7 min readJun 5, 2020
How to find duplicate elements in an array?

Hello guys, An array is the most fundamental data structure, which stores elements at a contiguous memory location. It is also one of the darling topics of interviewers and you will hear a lot of questions about an array in any coding interview, like reversing an array, sorting the array, or searching elements on the array.

The key benefit of an array data structure is that it offers fast O(1) search if you know the index, but adding and removing an element from an array is slow because you cannot change the size of the array once it’s created.

In order to create a shorter or longer array, you need to create a new array and copy all elements from old to new.

Things Every Programmer should know about Array

  1. Array index starts at 0, not 1.
  2. Array are mostly immutable data structure whose length cannot be changed once created, the mutable array is called list.
  3. The array needs a memory block for allocation, called consecutive memory location, this means even if you have a memory you cannot allocate a big array if memory is scattered.
  4. Searching by index in the array is O(1) but insert and delete is not easy because you may need to re-arrange the array.
  5. An array is mostly homogenous data structure this means you cannot store a string in an integer array and vice-versa.
  6. An array can be single dimension or multiple dimension. A two-dimensional array is known as Matrix and very useful in games to create 2D world using tiles.

The key to solving array-based questions is having a good knowledge of array data structure as well as basic programming constructors such as loop, recursion, and fundamental operators.

If you are not familiar with these concepts then I strongly suggest you to first go through a comprehensive data structure and algorithm course like Data Structures and Algorithms: Deep Dive Using Java which explains essential data structure in detail. It’s also very affordable as you can purchase this course on just $9.9 on crazy Udemy sales which happen every now and then.

20+ Array Questions from Programming Interviews

Here are some of the popular array-based coding interview questions for your practice:

  1. How do you find the missing number in a given integer array of 1 to 100? (solution)
  2. How do you find the duplicate number on a given integer array? (solution)
  3. How do you find the largest and smallest number in an unsorted integer array? (solution)
  4. How do you find all pairs of an integer array whose sum is equal to a given number? (solution)
  5. How do you find duplicate numbers in an array if it contains multiple duplicates? (solution)
  6. How to remove duplicates from a given array in Java? (solution)
  7. How do you search a target value in a rotated array? (solution)
  8. Given an unsorted array of integers, find the length of the longest consecutive elements sequence? (solution)
  9. How is an integer array sorted in place using the quicksort algorithm? (solution)
  10. How do you remove duplicates from an array in place? (solution)
  11. How do you reverse an array in place in Java? (solution)
  12. How are duplicates removed from an array without using any library? (solution)
  13. How to convert a byte array to String? (solution)
  14. What is the difference between an array and a linked list? (answer)
  15. How do you perform a binary search in a given array? (solution)
  16. How to find a median of two sorts arrays? (solution)
  17. How to rotate an array left and right by a given number K? (solution)
  18. How do you find duplicates from an unsorted array? (solution)
  19. Given an array of integers sorted in ascending order, find the starting and ending position of a given value? (solution)
  20. Given an integer array, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum? (solution)

These questions will not only help you to develop your problem-solving skills but also improve your knowledge of the array data structure.

If you need more advanced questions based upon array then you can see also see LeetCode In Python: 50 Algorithms Coding Interview Questions, a bootcamp style course to learn problem-solving techniques, data structures and algorithms to pass the coding interview at companies like google

In this course, the Author has compiled 50 of the most important and the most popular interview questions asked by these major companies and I explain them, in a true STEP BY STEP fashion to help you understand exactly how to solve these types of questions.

And, if you feel these 20 questions are not enough and you need more practice, then you can also check out this list of 30 array questions.

Best Resources for Coding Interviews

The selection of good resources is very important for success in your coding interviews. If you chose a wrong resource then more than money, you will lose valuable time you need for preparation, hence spend some time researching for good resources.

If you need recommendations, following are some of my the tried and tested resources to learn Data Structure and Algorithms in-depth for coding interviews:

And, if you prefer books, there is no better than the Cracking The Coding Interview, by Gayle Laakmann McDowell which presents 189+ Programming questions and solutions. A good book to prepare for programming job interviews in a short time. Btw, I will also earn some money if you buy any of these resources mentioned here.

Now You’re Ready for the Coding Interview

These are some of the most common questions outside of data structure and algorithms that help you to do really well in your interview.

I have also shared a lot of these questions on my blog, so if you are really interested, you can always go there and search for them.

These common coding, data structure, and algorithm questions are the ones you need to know to successfully interview with any company, big or small, for any level of programming job.

If you are looking for a programming or software development job then, you can start your preparation with this list of coding questions.

This list provides good topics to prepare and also helps assess your preparation to find out your areas of strength and weakness.

Good knowledge of data structure and algorithms is important for success in coding interviews and that’s where you should focus most of your attention.

Other Programming and Coding Interview Articles you may like

  1. 25 Software Design Problems from Coding interviews
  2. 21 String Coding Problems from Interviews
  3. 10 Algorithm Books Every Programmer Should Read
  4. 20+ binary tree problems from coding interviews
  5. Top 5 Data Structure and Algorithm Books for Java Developers
  6. 20+ linked list based coding problems from Programming interviews
  7. 100+ Coding Problems for Beginners and Experienced Programmers
  8. 10 Courses to Crack Your Next Coding Interview
  9. 20+ Java Interview Questions from Investment banks
  10. 30+ System Design Interview Questions for Programmers

Closing Notes

Thanks, You made it to the end of the article … Good luck with your programming interview! It’s certainly not going to be easy, but by following this roadmap and guide, you are one step closer to becoming a Software Developer.

If you like this article, then please share it with your friends and colleagues, and don’t forget to follow javinpaul on Twitter!

P.S. — If you need some FREE resources, you can check out this list of free data structure and algorithm courses to start your preparation.

and, if you want to learn System Design as well, then ByteByteGo is my discovery, its a great plateform to learn essential System Design concepts and architecture.

--

--

javinpaul
Javarevisited

I am Java programmer, blogger, working on Java, J2EE, UNIX, FIX Protocol. I share Java tips on http://javarevisited.blogspot.com and http://java67.com