Riverbed Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




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

i think it should be 9999*9901 = 9900 0099

since we're looking for the largest palindrome no, it's natural to take 9999
as one of the factors.

mul by 9999 is easy, ie.: x * 9999 = x * 10000 - x

hence we need to find the largest 4-digit no, say, 'abcd', s.t.,

abcd 0000 - abcd = mnpq qpnm
from this equation one can derive that it is 9901

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

in particular the last equation implies:

a + d = 10
b + c = 9

hence other palindromes could be: 8812 * 9999
or 9811 * 9999 but 9901 * 9999 is the largest

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

How did you arrive at the equations above ?

- user32456 May 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

{{since we're looking for the largest palindrome no, it's natural to take 9999 as one of the factors.}}
may not be a valid assumption.
999*100 < 998*101, which aren't palindromes actually, but the case here is similar

- Jagat September 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Irrelevant.

You can write a program to find the largest palindromic binary representation that results from multiplying numbers together without converting to string. But you can't find the largest arabic numeral palindrome without converting to string because arabic numeral are chars.

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

#include <stdio.h>
#include <stdbool.h>
#include <math.h>

int main (int argc, char *argv[]){
bool found = false;
  for (int i = 998; i >= 100; i--)
  {
    char j[7];
    sprintf(j,"%d",i);
    j[3]= j[2];
    j[4]= j[1];
    j[5]= j[0];
    int x =atoi(j);
    int limit = sqrt((float) x);
    for (int z = 999; z >= limit; z--)
    {
      if (x%z==0){
        printf("%d",x);
        found = true;
        break;
      }
    }
    if (found) break;
  }
}

http://stackoverflow.com/questions/3250957/finding-the-largest-palindrome-of-the-product-of-two-three-digit-numbers-problem

- dss.chandra March 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
void LargestPalindrome()
{
unsigned int Res = 0;
unsigned int A = MyPow(10,7) + 1;
unsigned int B = MyPow(10,6) + MyPow(10,1);
unsigned int C = MyPow(10,5) + MyPow(10,2);
unsigned int D = MyPow(10,4) + MyPow(10,3);


for(unsigned int i = 9999; i >= 1000; i--)
{
for(unsigned int a = 9; a >= 1; a--)
{
for(int b = 9; b >= 0; b--)
{
for(int c = 9; c >= 0; c--)
{
for(int d = 9; d >= 0; d--)
{
Res = A*a + B*b + C*c + D*d;

if(Res % i == 0 && Res / i <= 9999)
{
cout << i << " " << Res << " " << Res / i << endl;
return;
}
}
}
}
}
}
}
}

- Guy April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As noted elsewhere, a 6-digit base-10 palindrome abccba is a multiple of 11. This is true because a*100001 + b*010010 + c*001100 is equal to 11*a*9091 + 11*b*910 + 11*c*100. So, in our inner loop we can decrease n by steps of 11 if m is not a multiple of 11.

- iwanna March 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool ispalin (long num){
   long newnum=0;
   long tmp;
   int digit;
   while(num) {
       digit = num%10;
       num = num/10;
       newnum = newnum + digit*10;
    }
    if (num == newnum)
      return 1;
    else
      return 0;

}

long findlargestpalin () {
    res = 0;
    for (i = 9999 ; i > 1001 ; i--) {
        for (j = i ; j > 1000; j = j - 11) {
             if (j%11!=0) {
                 div = j/11;
                 j = div * j;
             }
             prod = i*j;
             if (ispalin(prod) && prod > res)
                 res = prod;
        }
    }
    return res;
}

- iwanna March 05, 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