Microsoft Interview Question 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;
}

- geniusxsy on November 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This seems precise answer.

- Gajanan on February 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- geniusxsy on November 09, 2009 | Flag Reply
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?

- particularraj on November 09, 2009 | Flag Reply
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;
}

- theory on November 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- anon on November 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sloppy code.
u really need to practice more coding

- geniusxsy on November 09, 2009 | Flag
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;
}

- geniusxsy on November 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

dude you are just reversing it. NOT checking it.

- Raj on November 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- srini on February 12, 2010 | Flag
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;
}

- Tejas on November 09, 2009 | Flag Reply
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);
}

- QQQ on November 12, 2009 | Flag Reply
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;
}

- nPcomplete on November 26, 2009 | Flag Reply
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

- Bhushan on December 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- kunalchopra on December 31, 2009 | Flag
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));
}
}

- Anonymous on May 21, 2010 | Flag Reply
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;
}

- NKD on July 11, 2010 | Flag Reply
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;


}

- Arun Kumar on October 16, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through 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