## Riverbed Interview Question for Software Engineer / Developers

• 0

Country: United States
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
6
of 6 vote

Perhaps as 999999 overflows to 000000 , is the answer 1 ?

Comment hidden because of low score. Click to expand.
0

huh that's the tricky question..
otherwise what the hell we need the story about the car odometer for ? ))

Comment hidden because of low score. Click to expand.
2
of 2 vote

11 always irrespective of the number of digits
00 - 11
090 - 101
0990 - 1001
09990 - 10001
etc.,

Comment hidden because of low score. Click to expand.
0

wrong!! from 101 - 111 there only 10 digits

Comment hidden because of low score. Click to expand.
0

101 to 111 is the only exception for his method.
I learnt a lot,
Thanks so much!!!

Comment hidden because of low score. Click to expand.
0

101 to 111 is the only exception for his method.
I learnt a lot,
Thanks so much!!!

Comment hidden because of low score. Click to expand.
0

101 to 111 is the only exception for his method.
I learnt a lot,
Thanks so much!!!

Comment hidden because of low score. Click to expand.
1
of 1 vote

Depends on the number of digits in the odometer, the answer is different.
1 digit -> 1, from n->n+1
2 digits -> 11, from nn->(n+1)(n+1)
3 digits -> 10, from xnx -> x(n+1)x
4+ digits -> 11, from n99n->(n+1)00(n+1)

Comment hidden because of low score. Click to expand.
0
of 0 vote

@Jay has got the right answer

Comment hidden because of low score. Click to expand.
0
of 0 vote

000 - 010 = 10 miles

Comment hidden because of low score. Click to expand.
0
of 0 vote

are not we suppose to write the code to solve this problem? Input is given as a past number and based on that next number should be determined? If it's just for this one tricky question, the question loses it's charm.

Comment hidden because of low score. Click to expand.
0
of 0 vote

The way I saw it,

if the current reading is 12321
then we start at the middle digit, in this case 3
then the new number becomes 12421 which is the next smallest palindromic number.

If the number of digits is even like 123321
then we take two middle digits in this case 3 and 3
and add 1 to both which becomes 124421.
In case of 9's we process it a little differently

eg 1239321
here middle digit is 9
so instead of adding 1 to it, we put 0 in that position
and look at next and previous digits of 9 in that number.
In this case they are 3 and 3.
so we can add 1s to both of them, so we put 1s in those places
and then append the 0s to complete the number.
Here final number will be 10100 which gives us palindromic number 1249421
Number 99999... is a special case. Just adding 2 to this number will give us the answer.
Here's the C code for it.
Please let me know if I missed something.
(The code assumes that we get he reading in the form of an array of integers)

``````double palindRead( const int * reading,
const int n ) //size of the array
{
//if the odometer reading is just 1 digit
if(n < 2) {
return 2;
} else {
return 1;
}
}

int index1, index2;
double result;

index1 = n/2;
if(n%2 != 0) {
index2 = index1;
result = pow(10,(n-index2-1));
} else {
index2 = index1 - 1;
result = pow(10, (n-index2-1)) + pow(10, (n-index1-1));
}
printf("%f\n", result);
printf("%d\n", index1);
printf("%d\n", index2);
while(index1 < n) {
break;
} else if(index1 == n-1
return 2;
} else {
index2--;
index1++;
result = pow(10, (n-index2-1)) + pow(10, (n-index1-1));
}
}

return result;

}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.