abhijeet15oct
BAN USER
Comments (3)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
int[] incrementArray(int arr[], int size){
if(arr == null || size < 1)
return;
int i = size-1;
arr[i]++;
while( arr[i] > 9)
{
arr[i] = arr[i] - 9;
i--;
if ( i >= 0)
arr[i]++;
else{
int[] newArr = new int[size + 1];
newArr[0] = 1;
for (int j=1; j<size+1; j++)
newArr[j]=arr[j];
return newArr;
}
}
return arr;
}
- abhijeet15oct February 28, 2012Comment hidden because of low score. Click to expand.
0
of 0 vote
void sortArray (int arr[], int size){
int i=0, j=size-1;
while(i<j){
if(arr[i] == 1 and arr[j]== 0)
swap(arr,i,j);
i++; j--;
else if(arr[i] == 0)
i++;
else if(arr[j] == 1)
j--;
}
}
- abhijeet15oct February 28, 2012Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
The idea is divide the cube into 8 sub-cubes and at each step we exclude a sub-cube based on mid-value of the main cube.
We split the cube into 1/8 and 7/8 at each step. It will be O(lg n) complexity alogrithm.
Code:
- abhijeet15oct February 28, 2012