chensheng@biheap.com:~$

  • Leaders-in-an-array

    ```java void printLeaders(int arr[], int size) { int max_from_right = arr[size - 1];

  • Find the Number Occurring Odd Number of Times

    int getOddOccurrence(int ar[], int ar_size)
    {
    	int res = 0;
    	for (int i = 0; i < ar_size; i++)
    	{
    		res = res ^ ar[i];
    	}
    	return res;
    }
    

  • Find the minimum distance between two numbers

    ```java int minDist(int arr[], int n, int x, int y) { int i = 0; int min_dist = Integer.MAX_VALUE; int prev = 0;

  • Pythagorean Triplet in an array

    ```java boolean isTriplet(int arr[], int n) { for (int i = 0; i < n; i++) { arr[i] = arr[i] * arr[i]; }

  • Find a peak element

    ```java int findPeakUtil(int arr[], int low, int high, int n) { int mid = low + (high - low) / 2;

  • Find-a-fixed-point-in-a-given-array

    ```java int binarySearch(int arr[], int low, int high) { if (high >= low) { int mid = (low + high) / 2; if (mid == arr[mid]) { return mid; } if (mid > arr[mid]) { return binarySearch(arr, (mid + 1), high); } else { return binarySearch(arr, low, (mid - 1)); } }

  • Count-strictly-increasing-subarrays

    ```java int countIncreasing(int n) { int cnt = 0;

  • Template

    ```java