Riverbed Interview Question for Software Engineer / Developers


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 ?

- Jay January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous January 28, 2012 | Flag
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.,

- Ravi January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong!! from 101 - 111 there only 10 digits

- danielpiedrahita January 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- oceanmaster January 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- oceanmaster January 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- oceanmaster January 25, 2012 | Flag
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)

- bluesun January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Jay has got the right answer

- InterviewSkills January 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

000 - 010 = 10 miles

- JB November 29, 2012 | Flag Reply
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.

- Tyrion Lannister May 23, 2013 | Flag Reply
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
and add 1 to it
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) {
                if(reading[0] == 9) {
                        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) {
                if(reading[index1]+1 < 10
                   && reading[index2]+1 < 10) {
                        break;
                } else if(index1 == n-1
                          && reading[index1] == 9) {
                        return 2;
                } else {
                        index2--;
                        index1++;
                        result = pow(10, (n-index2-1)) + pow(10, (n-index1-1));
                }
        }

        return result;

}

- rohit January 15, 2014 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More