Complete and full answer in order to give credit Thank you G

Complete and full answer in order to give credit. Thank you.

Given a sequence of n integers and suppose we know that there is at least one pair of two identical numbers. Design an efficient algorithm that finds such a pair of integers.

Solution

Please find the below code according to your requirement.

Code:

#include <bits/stdc++.h>

using namespace std;

// Returns number of pairs

int getPairsCount(int arr[], int n, int sum)

{

    // Consider all possible pairs

    for (int i=0; i<n; i++)

        for (int j=i+1; j<n; j++)

            if (arr[i] == arr[j])

   return a[i];

}

// Main function to test the above function

int main()

{

    int arr[] = {1, 5, 7, -1, 5} ; //user input

    int n = sizeof(arr)/sizeof(arr[0]);

    cout << \"Count of pairs is \" << getPairsCount(arr, n );

    return 0;

}

Complete and full answer in order to give credit. Thank you. Given a sequence of n integers and suppose we know that there is at least one pair of two identical

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site