MJ
BAN USER
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
Traverse the given number from rightmost digit, keep traversing till you find a digit which is smaller than the previously traversed digit.
Swap the digits.
Sort the digits right to the swapped index.
String findNextNumber(char[] n)
{
String next = null;
char lastDigit = n[n.length -1];
int i = n.length -2;
for( ; i >= 0 ; i -- )
{
if(n[i] < lastDigit){
{
swap(n, i, n.length -1);
sortArray(n, i+1);
next = String.valueOf(n);
break;
}
}
}
return next;
}
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
pushZeroToFront(int[] a)
- MJ December 13, 2015{
int zerocount = 0;
int count = a.length-1;
for(int i = a.length-1; i>=0; i--)
{
if(a[i] != 0)
a[count--]= a[i];
else
zerocount++;
}
for(int j = zerocount; j>0 && count >=0; j--)
{
a[count--] = 0;
}
}