Microsoft Interview Question for Software Engineer / Developers

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

void palindrome(int n){
int reverse_n=0, int tempn=n;
while(n){
reverse_n*=10;
reverse_n+=n%10;
n/=10;
}
return tempn==reverse_n;
}

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

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

reverse, compare.
what is 6 decimal system??? base_6 representation?

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

how can you reverse a number? You have to change it to a string?

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

``````// count the number of digits.
count=0;
while(n) {++count;n/=10}

// now compare digits
for(i=1;i<count/2;++i){
if(n/pow(10,count-i) != n % pow(10,i)
return false;
}``````

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

i=1;i<=count/2;i++

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

sloppy code.
u really need to practice more coding

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

void palindrome(int n){
int reverse_n=0, int tempn=n;
while(n){
reverse_n*=10;
reverse_n+=n%10;
n/=10;
}
return tempn==reverse_n;
}

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

dude you are just reversing it. NOT checking it.

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

geniusxsy's code is right...
but just change the return type...(raj might be confused)

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

Here is the logic,

bool palindrome(int n){

int reverseNumber = 0, constantFactor = 10, remainder = 0;
int originalNumber = n;

while(n){
remainder = n%constantFactor;
n /= 10;

reverseNumber = remainder + reverseNumber * constantFactor;
}

return originalNumber == reverseNumber;
}

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

private static bool isP(int n)
{
int m = n;
int p = 0;

while (n > 0)
{
p = p * 10 + n % 10;
n /= 10;
}
return (m == p);
}

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

int palindrome(int n)
{
int rev = 0;
int tmp = n;
int k;
while(tmp!=0)
{
k = tmp%10;
tmp = tmp/10;
rev = rev*10;
rev = (rev+k);
}
printf("rev--%d \n",rev);
while(rev!=0)
{
if(rev%10 !=n%10)
return 0;
rev = rev/10;
n = n/10;
}
return 1;
}

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

Algo:
1: convert the number into staring using itoa, ltoa or whatever suitable in-built function
2: take size of the string, n
3: then compare the i and n-i positions, increment i everytime till you reach the half

please correct me if i am wrong

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

wrong, no conversion to string allowed. cannot use an array.

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

bool palindrome(int num){
int reversenum, remainder;
int tmp=num;
if(tmp>0){

while(tmp)
{
remainder=tmp%10;
tmp=tmp/10;
reversenum=reversenum*10+remainder;
}
return (!(num^reversenum));
}
}

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

bool palindrome(int n)
{
int m = 1;
int x = n/10;
while(x)
{
m *=10;
x/=10;
}
bool Ispalindrome = true;
while(n)
{
if((n/m) != (n%10))
{
Ispalindrome = false;
break;
}
n %= m;
n /=10;
m /=100;
}
return Ispalindrome;
}

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

``````int reverse(int input)
{
int num = 0;
int mul = 1;
while(input !=0)
{
num = num*mul + (input - (input/10)*10);
mul = mul*10;
input = input/10;

}

return num;
}

int main()
{
int n1, n2;
cin>>n1;

n2 = reverse(n1);

if(n1^n2 == 0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;

}``````

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.