## Riverbed Interview Question for Software Engineer / Developers

• 0

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

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

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

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

How did you arrive at the equations above ?

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

{{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

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.

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;
sprintf(j,"%d",i);
j= j;
j= j;
j= j;
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

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;
}
}
}
}
}
}
}
}

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.

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;
}``````

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.