Array


  1. Count occurrences

    Given an array arr[] and an integer target, find the number of occurrences of target in the array. The implementation scans every element, so the input does not need to be sorted.

  2. Find duplicate

    Given an array of n integers with duplicate, output unique numbers of the array.

  3. Find the majority element in the array

    Given an array array, find the majority element that appears more than half times in the array. If no majority exists, return -1.

  4. Find minimum and maximum of an array

    Given an array of numbers, find the minimum and maximum elements by scanning the array once.

  5. Move negative to the beginning

    An array has both positive and negative numbers in random order. Rearrange the array elements to move all negative numbers before all positive numbers.

  6. Find peak element in array

    Find the index of any peak element in a given array. A peak element is an element that is strictly greater than both of its immediate neighbors. The first and last elements of the array are considered to be adjacent to negative infinity. If multiple peaks exist, return the index of any one of them.

  7. Reverse an array

    Given an array, reverse the order of its elements in place and return the reversed array.

  8. Cyclically rotate

    Given an array, cyclically rotate the array left by one position. The first element moves to the end of the array.

  9. Sort an array of 0s, 1s and 2s

    Given an array arr[] consisting of only 0s, 1s, and 2s. Sort the array, i.e., put all 0s first, then all 1s and all 2s in last.

  10. Sort array

    Given an array of integers arr, sort the array without using any built-in functions.