Skip to content

evilprince2009/10-Array-Coding-Questions

Repository files navigation

10 Popular array coding questions and their solutions

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, e.g. 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.

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.

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

  • How do you find the missing number in a given integer array of 1 to 100 ? (solution -> GetMissingNumber(int[] given_array): int)
  • How do you find the duplicate numbers on a given integer array ? (solution -> GetDuplicateNumbers(int[] given_array): int[])
  • How do you find the largest and smallest number in an unsorted integer array ? (solution -> LargestNumber(int[] array): int , SmallestNumber(int[] array): int)
  • How do you find how many pairs are there in an integer array whose sum is equal to a given number? (solution -> PairCount(int[] array, int sum): int)
  • How do you find duplicate numbers in an array if it contains multiple duplicates? (solution -> GetDuplicateNumbers(int[] given_array): int[])
  • How are duplicates removed from a given array ? (solution -> RemoveDuplicates(given_array): int[])
  • How is an integer array sorted in place ? ( -> Sort(int[] array): void)
  • How do you test if an array contains a specific value ? (solution -> Contains(int[] array, int value): bool)
  • How do you reverse an array in place in ? (solution -> Reverse(int[] array): void)
  • How are duplicates removed from an array without using any library ? (solution -> RemoveDuplicates(given_array): int[])

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

For solutions check out the the method in Code file with the same name as the question.

⚡⚡ Ibne Nahian ⚡⚡