Banana-Leopard/TASTY huggingface dataset:
//C++ code of Naive approach to
//find subarray with minimum average
 
#include<bits/stdc++.h>
using namespace std;
//function to find subarray
void findsubarrayleast(int arr[],int k,int n){
    int min=INT_MAX,minindex;
    for (int i = 0; i <= n-k; i++)
    {
        int sum=0;
        for (int j = i; j < i+k; j++)
        {
            sum+=arr[j];
        }
        if(sum<min){
            min=sum;
            minindex=i;
        }
         
    }
  //printing the desired subarray
    cout<<"subarray with minimum average is: ";
    for (int i = minindex; i < minindex+k; i++)
    {
        cout<<arr[i]<<" ";
    }
    
     
}
//driver code
int main() {
int arr[]={3, 7, 90, 20, 10, 50, 40};
int n=sizeof(arr)/sizeof(arr[0]),k=3;
//function call
findsubarrayleast(arr,k,n);
return 0;
}
 
//this code is contributed by Machhaliya Muhammad

Time complexity: quadratic
Space complexity: constant
// A Simple C++ program to find minimum average subarray
#include <bits/stdc++.h>
using namespace std;
 
// Prints beginning and ending indexes of subarray
// of size k with minimum average
void findMinAvgSubarray(int arr[], int n, int k)
{
    // k must be smaller than or equal to n
    if (n < k)
        return;
 
    // Initialize  beginning index of result
    int res_index = 0;
 
    // Compute sum of first subarray of size k
    int curr_sum = 0;
    for (int i = 0; i < k; i++)
        curr_sum += arr[i];
 
    // Initialize minimum sum as current sum
    int min_sum = curr_sum;
 
    // Traverse from (k+1)'th element to n'th element
    for (int i = k; i < n; i++) {
        // Add current item and remove first item of
        // previous subarray
        curr_sum += arr[i] - arr[i - k];
 
        // Update result if needed
        if (curr_sum < min_sum) {
            min_sum = curr_sum;
            res_index = (i - k + 1);
        }
    }
 
    cout << "Subarray between [" << res_index << ", "
         << res_index + k - 1 << "] has minimum average";
}
 
// Driver program
int main()
{
    int arr[] = { 3, 7, 90, 20, 10, 50, 40 };
    int k = 3; // Subarray size
    int n = sizeof arr / sizeof arr[0];
    findMinAvgSubarray(arr, n, k);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to Find the minimum
// distance between two numbers
#include <bits/stdc++.h>
using namespace std;
 
int minDist(int arr[], int n, int x, int y)
{
    int i, j;
    int min_dist = INT_MAX;
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if ((x == arr[i] && y == arr[j]
                 || y == arr[i] && x == arr[j])
                && min_dist > abs(i - j)) {
                min_dist = abs(i - j);
            }
        }
    }
    if (min_dist > n) {
        return -1;
    }
    return min_dist;
}
 
/* Driver code */
int main()
{
    int arr[] = { 3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int x = 3;
    int y = 6;
 
    cout << "Minimum distance between " << x << " and " << y
         << " is " << minDist(arr, n, x, y) << endl;
}
 
// This code is contributed by Shivi_Aggarwal

Time complexity: quadratic
Space complexity: constant
// C++ implementation of above approach
#include <bits/stdc++.h>
using namespace std;
 
int minDist(int arr[], int n, int x, int y)
{
         
    //previous index and min distance
    int p = -1, min_dist = INT_MAX;
     
    for(int i=0 ; i<n ; i++)
    {
        if(arr[i]==x || arr[i]==y)
        {
            //we will check if p is not equal to -1 and
            //If the element at current index matches with
            //the element at index p , If yes then update
            //the minimum distance if needed
            if( p != -1 && arr[i] != arr[p])
                min_dist = min(min_dist , i-p);
              
            //update the previous index
            p=i;
        }
    }
    //If distance is equal to int max
    if(min_dist==INT_MAX)
        return -1;
 
    return min_dist;
}
 
/* Driver code */
int main()
{
    int arr[] = {3, 5, 4, 2, 6, 3, 0, 0, 5, 4, 8, 3};
    int n = sizeof(arr) / sizeof(arr[0]);
    int x = 3;
    int y = 6;
 
    cout << "Minimum distance between " << x <<
                        " and " << y << " is "<<
                        minDist(arr, n, x, y) << endl;
    return 0;
}
 
// This code is contributed by Mukul singh.

Time complexity: linear
Space complexity: constant
// C++ program to Find the minimum
// distance between two numbers
#include <bits/stdc++.h>
using namespace std;
  
int minDist(int arr[], int n, int x, int y)
{
    //idx1 and idx2 will store indices of
    //x or y and min_dist will store the minimum difference
    int idx1=-1,idx2=-1,min_dist = INT_MAX;
    for(int i=0;i<n;i++)
    {
       //if current element is x then change idx1
       if(arr[i]==x)
       {
          idx1=i;
       }
       //if current element is y then change idx2
       else if(arr[i]==y)
       {
          idx2=i;
       }
       //if x and y both found in array
       //then only find the difference and store it in min_dist
       if(idx1!=-1 && idx2!=-1)
       min_dist=min(min_dist,abs(idx1-idx2));
    }
     
    //if left or right did not found in array
    //then return -1
    if(idx1==-1||idx2==-1)
    return -1;
    //return the minimum distance
    else
    return min_dist;
}
  
/* Driver code */
int main()
{
    int arr[] = { 3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int x = 3;
    int y = 6;
  
    cout << "Minimum distance between " << x << " and " << y
         << " is " << minDist(arr, n, x, y) << endl;
}

Time complexity: linear
Space complexity: constant
// C++ Code for the Approach
  
#include <bits/stdc++.h>
using namespace std;
  
// User function Template
int getMinDiff(int arr[], int n, int k)
{
    sort(arr, arr + n);
  
    // Maximum possible height difference
    int ans = arr[n - 1] - arr[0];
  
    int tempmin, tempmax;
    tempmin = arr[0];
    tempmax = arr[n - 1];
  
    for (int i = 1; i < n; i++) {
  
        // If on subtracting k we got
        // negative then continue
        if (arr[i] - k < 0)
            continue;
  
        // Minimum element when we
        // add k to whole array
        tempmin = min(arr[0] + k, arr[i] - k);
  
        // Maximum element when we
        // subtract k from whole array
        tempmax = max(arr[i - 1] + k, arr[n - 1] - k);
  
        ans = min(ans, tempmax - tempmin);
    }
    return ans;
}
  
// Driver Code Starts
int main()
{
  
    int k = 6, n = 6;
    int arr[n] = { 7, 4, 8, 8, 8, 9 };
  
    // Function Call
    int ans = getMinDiff(arr, n, k);
    cout << ans;
}

Time complexity: nlogn
Space complexity: constant
// C++ program to find Minimum
// number of jumps to reach end
#include <bits/stdc++.h>
using namespace std;
 
// Function to return the minimum number
// of jumps to reach arr[h] from arr[l]
int minJumps(int arr[], int n)
{
 
    // Base case: when source and
    // destination are same
    if (n == 1)
        return 0;
 
    // Traverse through all the points
    // reachable from arr[l]
    // Recursively, get the minimum number
    // of jumps needed to reach arr[h] from
    // these reachable points
    int res = INT_MAX;
    for (int i = n - 2; i >= 0; i--) {
        if (i + arr[i] >= n - 1) {
            int sub_res = minJumps(arr, i + 1);
            if (sub_res != INT_MAX)
                res = min(res, sub_res + 1);
        }
    }
 
    return res;
}
 
// Driver Code
int main()
{
    int arr[] = { 1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9 };
    int n = sizeof(arr) / sizeof(arr[0]);
    cout << "Minimum number of jumps to";
    cout << " reach the end is " << minJumps(arr, n);
    return 0;
}
 
// This code is contributed
// by Shivi_Aggarwal

Time complexity: np
Space complexity: linear
// C++ program for Minimum number
// of jumps to reach end
#include <bits/stdc++.h>
using namespace std;
 
int min(int x, int y) { return (x < y) ? x : y; }
 
// Returns minimum number of jumps
// to reach arr[n-1] from arr[0]
int minJumps(int arr[], int n)
{
    // jumps[n-1] will hold the result
    int* jumps = new int[n];
    int i, j;
 
    if (n == 0 || arr[0] == 0)
        return INT_MAX;
 
    jumps[0] = 0;
 
    // Find the minimum number of jumps to reach arr[i]
    // from arr[0], and assign this value to jumps[i]
    for (i = 1; i < n; i++) {
        jumps[i] = INT_MAX;
        for (j = 0; j < i; j++) {
            if (i <= j + arr[j] && jumps[j] != INT_MAX) {
                jumps[i] = min(jumps[i], jumps[j] + 1);
                break;
            }
        }
    }
    return jumps[n - 1];
}
 
// Driver code
int main()
{
    int arr[] = { 1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9 };
    int size = sizeof(arr) / sizeof(int);
    cout << "Minimum number of jumps to reach end is "
         << minJumps(arr, size);
    return 0;
}
 
// This is code is contributed by rathbhupendra

Time complexity: np
Space complexity: linear
// C++ program to find Minimum number of jumps to reach end
#include <bits/stdc++.h>
using namespace std;
 
// Returns Minimum number of jumps to reach end
int minJumps(int arr[], int n)
{
    // jumps[0] will hold the result
    int* jumps = new int[n];
    int min;
 
    // Minimum number of jumps needed to reach last element
    // from last elements itself is always 0
    jumps[n - 1] = 0;
 
    // Start from the second element, move from right to
    // left and construct the jumps[] array where jumps[i]
    // represents minimum number of jumps needed to reach
    // arr[m-1] from arr[i]
    for (int i = n - 2; i >= 0; i--) {
        // If arr[i] is 0 then arr[n-1] can't be reached
        // from here
        if (arr[i] == 0)
            jumps[i] = INT_MAX;
 
        // If we can directly reach to the end point from
        // here then jumps[i] is 1
        else if (arr[i] >= n - i - 1)
            jumps[i] = 1;
 
        // Otherwise, to find out the minimum number of
        // jumps needed to reach arr[n-1], check all the
        // points reachable from here and jumps[] value for
        // those points
        else {
            // initialize min value
            min = INT_MAX;
 
            // following loop checks with all reachable
            // points and takes the minimum
            for (int j = i + 1; j < n && j <= arr[i] + i;
                 j++) {
                if (min > jumps[j])
                    min = jumps[j];
            }
 
            // Handle overflow
            if (min != INT_MAX)
                jumps[i] = min + 1;
            else
                jumps[i] = min; // or INT_MAX
        }
    }
 
    return jumps[0];
}
 
// Driver program to test above function
int main()
{
    int arr[] = { 1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9 };
    int size = sizeof(arr) / sizeof(int);
    cout << "Minimum number of jumps to reach"
         << " end is " << minJumps(arr, size);
    return 0;
}
 
// This code is contributed by Sania Kumari Gupta

Time complexity: quadratic
Space complexity: linear
/* Dynamic Programming implementation
of Maximum Sum Increasing Subsequence
(MSIS) problem */
#include <bits/stdc++.h>
using namespace std;
 
/* maxSumIS() returns the maximum
sum of increasing subsequence
in arr[] of size n */
int maxSumIS(int arr[], int n)
{
    int i, j, max = 0;
    int msis[n];
 
    /* Initialize msis values
    for all indexes */
    for ( i = 0; i < n; i++ )
        msis[i] = arr[i];
 
    /* Compute maximum sum values
    in bottom up manner */
    for ( i = 1; i < n; i++ )
        for ( j = 0; j < i; j++ )
            if (arr[i] > arr[j] &&
                msis[i] < msis[j] + arr[i])
                msis[i] = msis[j] + arr[i];
 
    /* Pick maximum of
    all msis values */
    for ( i = 0; i < n; i++ )
        if ( max < msis[i] )
            max = msis[i];
 
    return max;
}
 
// Driver Code
int main()
{
    int arr[] = {1, 101, 2, 3, 100, 4, 5};
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "Sum of maximum sum increasing "
            "subsequence is " << maxSumIS( arr, n ) << endl;
    return 0;
}
 
// This is code is contributed by rathbhupendra

Time complexity: quadratic
Space complexity: linear
# include <iostream>
using namespace std;
 
// Returns length of smallest subarray with sum greater than x.
// If there is no subarray with given sum, then returns n+1
int smallestSubWithSum(int arr[], int n, int x)
{
    //  Initialize length of smallest subarray as n+1
     int min_len = n + 1;
 
     // Pick every element as starting point
     for (int start=0; start<n; start++)
     {
          // Initialize sum starting with current start
          int curr_sum = arr[start];
 
          // If first element itself is greater
          if (curr_sum > x) return 1;
 
          // Try different ending points for current start
          for (int end=start+1; end<n; end++)
          {
              // add last element to current sum
              curr_sum += arr[end];
 
              // If sum becomes more than x and length of
              // this subarray is smaller than current smallest
              // length, update the smallest length (or result)
              if (curr_sum > x && (end - start + 1) < min_len)
                 min_len = (end - start + 1);
          }
     }
     return min_len;
}
 
/* Driver program to test above function */
int main()
{
    int arr1[] = {1, 4, 45, 6, 10, 19};
    int x = 51;
    int n1 = sizeof(arr1)/sizeof(arr1[0]);
    int res1 = smallestSubWithSum(arr1, n1, x);
    (res1 == n1+1)? cout << "Not possible\n" :
                    cout << res1 << endl;
 
    int arr2[] = {1, 10, 5, 2, 7};
    int n2 = sizeof(arr2)/sizeof(arr2[0]);
    x  = 9;
    int res2 = smallestSubWithSum(arr2, n2, x);
    (res2 == n2+1)? cout << "Not possible\n" :
                    cout << res2 << endl;
 
    int arr3[] = {1, 11, 100, 1, 0, 200, 3, 2, 1, 250};
    int n3 = sizeof(arr3)/sizeof(arr3[0]);
    x  = 280;
    int res3 = smallestSubWithSum(arr3, n3, x);
    (res3 == n3+1)? cout << "Not possible\n" :
                    cout << res3 << endl;
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// O(n) solution for finding smallest subarray with sum
// greater than x
#include <iostream>
using namespace std;
 
// Returns length of smallest subarray with sum greater than
// x. If there is no subarray with given sum, then returns
// n+1
int smallestSubWithSum(int arr[], int n, int x)
{
    // Initialize current sum and minimum length
    int curr_sum = 0, min_len = n + 1;
 
    // Initialize starting and ending indexes
    int start = 0, end = 0;
    while (end < n) {
        // Keep adding array elements while current sum
        // is smaller than or equal to x
        while (curr_sum <= x && end < n)
            curr_sum += arr[end++];
 
        // If current sum becomes greater than x.
        while (curr_sum > x && start < n) {
            // Update minimum length if needed
            if (end - start < min_len)
                min_len = end - start;
 
            // remove starting elements
            curr_sum -= arr[start++];
        }
    }
    return min_len;
}
 
/* Driver program to test above function */
int main()
{
    int arr1[] = { 1, 4, 45, 6, 10, 19 };
    int x = 51;
    int n1 = sizeof(arr1) / sizeof(arr1[0]);
    int res1 = smallestSubWithSum(arr1, n1, x);
    (res1 == n1 + 1) ? cout << "Not possible\n"
                     : cout << res1 << endl;
 
    int arr2[] = { 1, 10, 5, 2, 7 };
    int n2 = sizeof(arr2) / sizeof(arr2[0]);
    x = 9;
    int res2 = smallestSubWithSum(arr2, n2, x);
    (res2 == n2 + 1) ? cout << "Not possible\n"
                     : cout << res2 << endl;
 
    int arr3[] = { 1, 11, 100, 1, 0, 200, 3, 2, 1, 250 };
    int n3 = sizeof(arr3) / sizeof(arr3[0]);
    x = 280;
    int res3 = smallestSubWithSum(arr3, n3, x);
    (res3 == n3 + 1) ? cout << "Not possible\n"
                     : cout << res3 << endl;
 
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to find maximum average subarray
// of given length.
#include<bits/stdc++.h>
using namespace std;
 
// Returns beginning index of maximum average
// subarray of length 'k'
int findMaxAverage(int arr[], int n, int k)
{
    // Check if 'k' is valid
    if (k > n)
        return -1;
 
    // Create and fill array to store cumulative
    // sum. csum[i] stores sum of arr[0] to arr[i]
    int *csum = new int[n];
    csum[0] = arr[0];
    for (int i=1; i<n; i++)
       csum[i] = csum[i-1] + arr[i];
 
    // Initialize max_sm as sum of first subarray
    int max_sum = csum[k-1], max_end = k-1;
 
    // Find sum of other subarrays and update
    // max_sum if required.
    for (int i=k; i<n; i++)
    {
        int curr_sum = csum[i] - csum[i-k];
        if (curr_sum > max_sum)
        {
            max_sum = curr_sum;
            max_end = i;
        }
    }
 
    delete [] csum; // To avoid memory leak
 
    // Return starting index
    return max_end - k + 1;
}
 
// Driver program
int main()
{
    int arr[] = {1, 12, -5, -6, 50, 3};
    int k = 4;
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "The maximum average subarray of "
         "length "<< k << " begins at index "
         << findMaxAverage(arr, n, k);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to find maximum average subarray
// of given length.
#include<bits/stdc++.h>
using namespace std;
 
// Returns beginning index of maximum average
// subarray of length 'k'
int findMaxAverage(int arr[], int n, int k)
{
    // Check if 'k' is valid
    if (k > n)
        return -1;
 
    // Compute sum of first 'k' elements
    int sum = arr[0];
    for (int i=1; i<k; i++)
        sum += arr[i];
 
    int max_sum = sum, max_end = k-1;
 
    // Compute sum of remaining subarrays
    for (int i=k; i<n; i++)
    {
        sum = sum + arr[i] - arr[i-k];
        if (sum > max_sum)
        {
            max_sum = sum;
            max_end = i;
        }
    }
 
    // Return starting index
    return max_end - k + 1;
}
 
// Driver program
int main()
{
    int arr[] = {1, 12, -5, -6, 50, 3};
    int k = 4;
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "The maximum average subarray of "
         "length "<< k << " begins at index "
         << findMaxAverage(arr, n, k);
    return 0;
}

Time complexity: linear
Space complexity: constant
/* C++ program to count minimum number of operations
   to get the given target array */
#include <bits/stdc++.h>
using namespace std;
 
// Returns count of minimum operations to convert a
// zero array to target array with increment and
// doubling operations.
// This function computes count by doing reverse
// steps, i.e., convert target to zero array.
int countMinOperations(unsigned int target[], int n)
{
    // Initialize result (Count of minimum moves)
    int result = 0;
 
    // Keep looping while all elements of target
    // don't become 0.
    while (1)
    {
        // To store count of zeroes in current
        // target array
        int zero_count = 0;
 
        int i;  // To find first odd element
        for (i=0; i<n; i++)
        {
            // If odd number found
            if (target[i] & 1)
                break;
 
            // If 0, then increment zero_count
            else if (target[i] == 0)
                zero_count++;
        }
 
        // All numbers are 0
        if (zero_count == n)
          return result;
 
        // All numbers are even
        if (i == n)
        {
            // Divide the whole array by 2
            // and increment result
            for (int j=0; j<n; j++)
               target[j] = target[j]/2;
            result++;
        }
 
        // Make all odd numbers even by subtracting
        // one and increment result.
        for (int j=i; j<n; j++)
        {
           if (target[j] & 1)
           {
              target[j]--;
              result++;
           }
        }
    }
}
 
/* Driver program to test above functions*/
int main()
{
    unsigned int arr[] = {16, 16, 16};
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "Minimum number of steps required to "
           "get the given target array is "
         << countMinOperations(arr, n);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to find number of operations
// to make an array palindrome
#include <bits/stdc++.h>
using namespace std;
 
// Returns minimum number of count operations
// required to make arr[] palindrome
int findMinOps(int arr[], int n)
{
    int ans = 0; // Initialize result
 
    // Start from two corners
    for (int i=0,j=n-1; i<=j;)
    {
        // If corner elements are same,
        // problem reduces arr[i+1..j-1]
        if (arr[i] == arr[j])
        {
            i++;
            j--;
        }
 
        // If left element is greater, then
        // we merge right two elements
        else if (arr[i] > arr[j])
        {
            // need to merge from tail.
            j--;
            arr[j] += arr[j+1] ;
            ans++;
        }
 
        // Else we merge left two elements
        else
        {
            i++;
            arr[i] += arr[i-1];
            ans++;
        }
    }
 
    return ans;
}
 
// Driver program to test above
int main()
{
    int arr[] = {1, 4, 5, 9, 1};
    int n = sizeof(arr)/sizeof(arr[0]);
    cout << "Count of minimum operations is "
         <<  findMinOps(arr, n) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to find the smallest positive value that cannot be
// represented as sum of subsets of a given sorted array
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
// Returns the smallest number that cannot be represented as sum
// of subset of elements from set represented by sorted array arr[0..n-1]
long long smallestpositive(vector<long long> arr, int n) {
   long long int res = 1; // Initialize result
  
   sort(arr.begin(), arr.end());
   // Traverse the array and increment 'res' if arr[i] is
   // smaller than or equal to 'res'.
   for (int i = 0; i < n && arr[i] <= res; i++)
       res = res + arr[i];
  
   return res;
  }
 
// Driver program to test above function
int main() {
   vector<long long> arr1 = {1, 3, 4, 5};
   cout << smallestpositive(arr1, arr1.size()) << endl;
  
   vector<long long> arr2 = {1, 2, 6, 10, 11, 15};
   cout << smallestpositive(arr2, arr2.size()) << endl;
  
   vector<long long> arr3 = {1, 1, 1, 1};
   cout << smallestpositive(arr3, arr3.size()) << endl;
  
   vector<long long> arr4 = {1, 1, 3, 4};
   cout << smallestpositive(arr4, arr4.size()) << endl;
  
   return 0;
 }

Time complexity: nlogn
Space complexity: constant
// C++ program to print length of the largest
// contiguous array sum
#include<bits/stdc++.h>
using namespace std;
 
int maxSubArraySum(int a[], int size)
{
    int max_so_far = INT_MIN, max_ending_here = 0,
       start =0, end = 0, s=0;
 
    for (int i=0; i< size; i++ )
    {
        max_ending_here += a[i];
 
        if (max_so_far < max_ending_here)
        {
            max_so_far = max_ending_here;
            start = s;
            end = i;
        }
 
        if (max_ending_here < 0)
        {
            max_ending_here = 0;
            s = i + 1;
        }
    }
     
    return (end - start + 1);
}
 
/*Driver program to test maxSubArraySum*/
int main()
{
    int a[] = {-2, -3, 4, -1, -2, 1, 5, -3};
    int n = sizeof(a)/sizeof(a[0]);
    cout << maxSubArraySum(a, n);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ implementation of simple method to find
// minimum difference between any pair
#include <bits/stdc++.h>
using namespace std;
 
// Returns minimum difference between any pair
int findMinDiff(int arr[], int n)
{
    // Initialize difference as infinite
    int diff = INT_MAX;
 
    // Find the min diff by comparing difference
    // of all possible pairs in given array
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
            if (abs(arr[i] - arr[j]) < diff)
                diff = abs(arr[i] - arr[j]);
 
    // Return min diff
    return diff;
}
 
// Driver code
int main()
{
    int arr[] = { 1, 5, 3, 19, 18, 25 };
    int n = sizeof(arr) / sizeof(arr[0]);
 
    // Function call
    cout << "Minimum difference is " << findMinDiff(arr, n);
    return 0;
}

Time complexity: quadratic
Space complexity: constant