Header Ads Widget

find the Product Id | Wipro programming question solution

 Problem:-

The company has to find the bucket ID from the product ID. The company needs an algorithm which takes the product ID as an input, calculates the smallest and largest permutation with the digits of the product ID, then outputs the sum of these smallest and largest permutations as the bucket ID.


Write an algorithm for the company to find the bucket ID for the given product.

Input:-
 The input consists of an integer- productID, representing the product ID of the product.

Output:-

Print an integer representing the bucket ID for the given product.

Example:-

Input:

734

Output:

1090

Explanation:

The smallest permutation with digits

734 is 347   so after adding these we will get 1090.

Code:-


#include <bits/stdc++.h>
using namespace std;

int main()
{
int n,small=0,large=0;
int a[100],i=0;
cin>>n;
while(n!=0)
{
int r=n%10;
a[i]=r;
n=n/10;
i++;
}
// sort the array
sort(a,a+i);
// finding the smallest element
for(int j=0;j<i;j++)
{
small=small*10+a[j];
}
// finding the greatest element
for(int j=i-1;j>=0;j--)
{
large=large*10+a[j];
}
cout<<small+large<<endl;
return 0;
}

Output:-

734
1090

Recommended Post:

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-


Wipro previous question paper solution , wipro previous year question papers with answers pdf,
wipro previous year questions, wipro question paper 2021,wipro online assessment test questions and answers,wipro model papers 2020,wipro previous year coding questions,wipro online assessment test questions and answers 2022,wipro aptitude questions with answers pdf,wipro question paper 2021,wipro model papers 2020,wipro previous year coding questions,10 wipro placement papers,
wipro previous year question papers with answers pdf



Post a Comment

0 Comments