Arrays

Here are Some Questions on Arrays that covers mostly all the topics related to Arrays.
We tried to provide some solutions with respective Time and Space complexities, there can be better solutions that exist.

  1. Find the Number Occurring Odd Number of Times.
  2. Find the Missing Number.
  3. Find Smallest Missing Number in an Array.
  4. Two elements whose sum is closest to zero.
  5. Reverse an Array.
    1. Write a program to reverse an array.
  6. Segregate Even and Odd numbers in an array.
    1. Segregate 0 and 1 in an array.
  7. Move all zeroes to the end of the Array.
  8. Maximum of all Sub-arrays of size K.
  9. Shuffle a given array.
  10. Find the Next Greatest Element (NGE) in an array.
  11. Replace every element with the greatest element on right side in an array.
  12. Rotate an array.
    1. Reversal Algorithm for Array Rotation.
    2. Block swap algorithm for array rotation.
  13. Search an Element in a Sorted and Rotated Array.
  14. Majority Element in an array.
    1. Majority Element in a Sorted Array.
  15. To check if an array has pair of elements with given sum.
  16. Smallest and second smallest element in an array.
  17. Maximum sum with no adjacent elements taken.
  18. Largest Sum Contiguous Subarray (Kadane’s Algorithm).
    1. Kadane’s Algorithm / Maximum Sum contiguous subarray.
  19. Maximum Product Subarray.
  20. Leaders in an Array.
  21. Counting Inversions in an array(Inversion Count).
  22. Find two Repeating Elements in an Array.
  23. Sort elements by frequency in an array.
  24. Counting sort.
  25. Pancake Sorting.
  26. Convert a Given Array to a Product Array.
  27. Minimum Length Unsorted Subarray, Sorting which makes the array Sorted.
  28. Maximum difference between two elements such that larger element appears after the smaller.
  29. Merge an Array of size n into Another of size m+n.
  30. Floor and Ceil of an element in a Sorted Array.
  31. Maximum and Minimum of an array using minimum comparisons.
  32. Number of Occurrences of a given Element in a Sorted Array.
  33. Find Fixed Point in a Given Array.
  34. Duplicates in an array in linear time and constant space.
  35. Union and Intersection of two sorted arrays.
  36. Sorting algorithm that makes the minimum number of memory writes.
  37. k largest elements in an array.
    1. k largest elements in an array using heaps.
  38. Check if Array Elements are Consecutive.
  39. Maximum Length Bitonic Subarray.
  40. The Maximum Element in an array which is first Increasing then Decreasing.
  41. Equilibrium index of an array.
  42. Find the maximum j – i such that arr[j] greater than arr[i].
  43. Find a Triplet in the Given Array that sums to a Given Value.
  44. Four Elements that sum to a Given Value in an Array.
  45. Find Pythagorean Triplet in an Array.
  46. Count Smaller Elements on the Right in an array.
  47. Find a pair with the given difference in an array.
  48. Sort an Array in Wave Form.
  49. Replace every array element by multiplication of previous and next.
  50. Smallest Subarray with sum greater than a given value.
  51. Print All Distinct Elements of the given Array.
  52. Delete an Array Element(using one and two traversals).
  53. Find number of pairs(x,y) in an array such that xy > yx.
  54. Construct an array from it’s pair sum array.
  55. Rearrange Positive and Negative numbers in an array.
  56. Arrange elements of given array to form largest number.
  57. Find position of an element in a sorted array of infinite numbers.
  58. Find minimum number of merge operations to make an array palindrome.

Matrix

  1. Turn an image by 90 degrees.