Adobe Interview Question for Software Engineer in Tests


Country: India




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

bool palindrome(int a)
{
int n=a,m=0;
if(a<0)n=-a
while(n>0)
{
m *= 10;
m += n%10;
n /= 10;
}
return((m==n)?true:false)
}

- Ali_BABA February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess last comparison would be

return((m==a)?true:false)
instead of
return((m==n)?true:false)

- Dewarist February 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

few more mistakes are there...
in while loop n never became < or = 0 (smallest value of n can be 1)
value of n changed in the while loop so you can not compare with m in return statement ...
etc.. those are the small changes...
so i re write the code

bool IsPalindrom(int a)
{
    int m = 0;
    if(a<0) a = -a;
    int n = a;

    while(n >9)
    {
        m += n%10;
        m *= 10;
        n /= 10;
    }
    m += n;
    return(m==a?true:false);
}

- Dewarist February 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why do you write this return((m==n)?true:false); ?
Why don't you write return m == n; ?

- Selmeczy, Péter February 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Here's another error. The evaluation of -x results in signed overflow when x is INT_MIN. In theory, this is undefined behavior, and the compiler can do anything it likes under those circumstances. In practice, it results in -x == x, which breaks invariants in the rest of your code.

This is a common mistake in routines which (like this one) take absolute values to normalize the input. The easy fix: unsigned int n = (unsigned int) a, m = 0; and remove 'if (a < 0) n = -a;' entirely.

- psykotic February 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome ( int num )
{
if ( fabs(num) < 10 ) return true;

int d = 1, temp = num;
while ( temp/10 )
{
temp /= 10;
d *= 10;
}

while ( num )
{
if ( num/d != num % 10 )
return false;

num -= ((num/d)*d);
num /= 10;
d /= 100;
}
return true;
}

- Muna February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome ( int num )
{
if ( fabs(num) < 10 ) return true;

int d = 1, temp = num;
while ( temp/10 )
{
temp /= 10;
d *= 10;
}

while ( num )
{
if ( num/d != num % 10 )
return false;

num -= ((num/d)*d);
num /= 10;
d /= 100;
}
return true;
}

- Muna February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome ( int num )
{
if ( fabs(num) < 10 ) return true;

int d = 1, temp = num;
while ( temp/10 )
{
temp /= 10;
d *= 10;
}

while ( num )
{
if ( num/d != num % 10 )
return false;

num -= ((num/d)*d);
num /= 10;
d /= 100;
}
return true;
}

- Muna February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome(int x,int rx=0)
{
  if(x>rx) return isPalindrome(x/10,rx*10+x%10);
  if(x<0) return isPalindrome((-x<0)?0:(-x),0);
  return (x==rx) || (x==rx/10);
}

- comonad February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool IsPalindrome (int num){
  if(num < 0) num = -num;

  int orig = num, rev = 0;
  while ( orig > 0 ){
    rev = rev * 10 + orig % 10;
    orig = orig / 10;
  }
  return rev == num;
}

- abhijeet February 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char a[80];
memset(a, '\0', 80);
printf("Enter a integer :");
scanf("%s", a);
int len = strlen(a);
int i = 0;
bool flag = true;
if(a[0] == '-')
i++;
for(int j = len-1;i <= len/2; i++, j--)
{
if(a[i] != a[j])
{
flag = false;
break;
}
}
printf("\n%d", flag);
}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PalinTest {
public static void main(String[] args) {
System.out.println("Please Enter the number");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(System.in));
try {
String integer = bufferedReader.readLine();

int j = integer.length();
int count=1;

for (int i = 0, l = j - 1; i < j - 1; i++, l--,count++) {
if (integer.charAt(i) != integer.charAt(l)) {
System.out.println("not a plaindrome");
break;
}

continue;



}
if(count==j)
{
System.out.println("Entered number is a palindrome");
}


} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

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

sorry forgot to handle negative integers..here is modified one:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PalinTest {
public static void main(String[] args) {
System.out.println("Please Enter the number");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(System.in));
try {
String integer = bufferedReader.readLine();

int j = integer.length();
int count = 1;

for (int i = 0, l = j - 1; i < j - 1; i++, l--, count++) {
if (integer.charAt(0) == '-') {
continue;
}

if (integer.charAt(i) != integer.charAt(l)) {
System.out.println("not a plaindrome");
break;
}

continue;

}
if (count == j) {
System.out.println("Entered number is a palindrome");
}

} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

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

sorry forgot to handle negative integers..here is modified one:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PalinTest {
public static void main(String[] args) {
System.out.println("Please Enter the number");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(System.in));
try {
String integer = bufferedReader.readLine();
int j = integer.length();
int count = 1;
for (int i = 0, l = j - 1; i < j - 1; i++, l--, count++) {
if (integer.charAt(0) == '-') {
continue;
}
if (integer.charAt(i) != integer.charAt(l)) {
System.out.println("not a plaindrome");
break;
}
continue;
}
if (count == j) {
System.out.println("Entered number is a palindrome");
}

} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

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

#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,k,r,rev=0;
printf("Enter the number\n");
scanf("%d",&n);
if(abs(n)<10)
printf("%d is a palindrome\n");
else
{
k=n;
while(k)
{
r=k%10;
rev=rev*10+r;
k=k/10;
}
if(rev==n)
printf("%d is a palindrome\n",n);
else
printf("%d is not a palindrome\n",n);
}
return 0;
}

- narayan kunal March 05, 2012 | 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