Computer Science, asked by PavanKumarG8756, 1 year ago

Find all the unique pairs from the unsorted array.

Answers

Answered by utkarshmishra9819
0

class prog {

int check(int n)

{String a=""+n;int y=0;

int l=a.length();int v[]=new int[l];

while(n>0)

{v[y]=n%10;

n=n/10;y++;

}

y=1;

for(int i=0;i<l-1;i++)

{

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

{

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

{y=0;

break;}

}

}

return y;

}

void main(int s[])

{

int u=s.length();

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

{

int r=check(s[i]);

if (r==1)

{

System.out.println(s[i]+"is a unique number");

}

}

}}

Hope this helps you.

I have put in quite an effort typing this on phone

please mark it as the brainliest answer.

Answered by Anonymous
0

/* A simple program to count pairs with difference k*/

using namespace std;  

 

int countPairsWithDiffK(int arr[], int n, int k)  

{  

   int count = 0;  

     

   // Pick all elements one by one  

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

   {        

       // See if there is a pair of this picked element  

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

           if (arr[i] - arr[j] == k || arr[j] - arr[i] == k )  

                 count++;  

   }  

   return count;  

}  

 

// Driver program to test above function  

int main()  

{  

   int arr[] =  {1, 5, 3, 4, 2};  

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

   int k = 3;  

   cout << "Count of pairs with given diff is "

        << countPairsWithDiffK(arr, n, k);  

   return 0;

}

Similar questions