Array


  1. Count occurrences

    Given a sorted array arr[] and an integer target, find the number of occurrences of target in given array.

  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 using minimum number of comparisons

    Given an array of numbers, find the minimum and the maximum element of the array using the minimum number of comparisons.

  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

    Reverse an array

  8. Cyclically rotate

    Given an array, cyclically rotate the array clockwise by one time.

  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.