Microsoft Interview Question for Software Engineer / Developers


Team: Bing
Country: India
Interview Type: In-Person




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

BAD;
26^2 * (B-A) + 26^1 * (A-A) + 26^0 * (D - A)

- abhishekatuw January 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

If you count like this, then AAA == 0
So I think you should use add +1 to (A-A) and e t.c.
Also you should add +1 to 26^2 because column index starts from 1 == A till 26 == Z so AA == 26^1 +1.
So the result will be smth like this:
BAD;
(26^2 + 1) * (B - A + 1) + (26^1 + 1) * (A - A + 1) + (26^0 + 1) * (D - A + 1)
Correct me if I am wrong

- goRGon February 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

int column(char *str)
{
int *p1,*p2;
p1=p2=str;
while(p2)p2++;
p2--//p2 ponting to last char of string and p1 to first char
int i=0,sum=0;
while(p2!=p1)
{
int k=(66-(int)(*p2));//converting char to corresponding integer eg. A=1,B=2,Z=26...
sum+=k*pow(26,i++);
}
return sum;
}

- Ali_BABA January 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

char[] charArray = "BAD".ToLower().ToCharArray();
int constant = 26;
int number = 0;
for (int i = 0; i < charArray.Length ; i++)
{
int multiplier = (charArray[i] - 'a') + 1;
number = number + (multiplier * constant);
}
//int i = Convert.ToInt16('b') - Convert.ToInt16('a');
Console.WriteLine(number.ToString());
Console.Read();

- Vinu February 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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

int isoperand (char e);

int main()
{
	char e[10];
	int i, j, x, n, powr;
	double sum = 0;
	printf("\nEnter the string\n");
	gets(e);
	n = strlen(e);
	printf("\n%d\n", n);
	for(i = n-1, j = 0; j <= n-1; i--, j++)
	{
		if(1 == isoperand(e[i]))
		{
			x = e[j] - 'A' + 1;
			sum = sum + (pow(26, i) * x);
		}
		else
			{
				printf("Wrong input");
				exit();	
			}
	}	
	printf("The string is %s and its equivalent number is %f", e, sum);
}

int isoperand(char e)
{
	if(e >= 'A' && e <= 'Z')
		return 1;
	else
		return 0;
}

- Prathamesh February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Strings are in base 26 with  A = 1, B = 2,.... Z = 26

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

This is exactly like converting a string to int.
While converting a string to integer, initially we keep the result as zero. Then multiply result by 10 and add the current digit (corresponding to the current character) to the result; We keep doing it until all the characters in the input string are visited.

The only change to this problem is,
1. We have to map the character from A-Z to 1-26
2. Start with result=0 and multiply result with 26 and then add the digit value corresponding to the current character.

Suppose if the input is 'BAD', then,

1. result = 0
2. result = (result*26) + 'B'-'A'+1 (adding 1 at the end so as to map 'A' to 1)
3. result = (result*26) + 'A'-'A'+1
4. result = (result*26) + 'D'-'A'+1

return result.

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

Wrong answer!!! for BAD the calculation is 2732 and the correct answer is 707.
I try with AB and the result is 53 and really is 28.
the correct answer to calculate the number is using the @abhishekatuw formula

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

the correct answer for the BAD should be 1382!! .its not 707.
the correct formula which i believe
BAD:
(B-A+1)*(26^2)+(A-A+1)*(26^1)+(D-A+1)*(26^0)
where A=1 B=2..... Z=26

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

@geeeks you are right I forget the +1 if no when the letter is A the result will be 0.

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

@ geeks, that is the right answer

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

For BAD should be 1382.
@geeeks ' s algoirthm is correct.
(B-A+1)*(26^2)+(A-A+1)*(26^1)+(D-A+1)*(26^0)

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

@geeks algorithm is wrong.
I see it actually calculates
(B-A+1)*(26^0)+(A-A+1)*(26^1)+(D-A+1)*(26^2)
which is wrong.

Correct one should be..
(B-A+1)*(26^2)+(A-A+1)*(26^1)+(D-A+1)*(26^0)

I checked the result for string 'BA'. Value returned should be 53 but @geeks formula returns 27.

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

int numberFromExcelColumnName(const char* pColName)
{
	int num = 0;
	for (const char* p = pColName; *p != '\0'; ++p)
		num = num * 26 + (*p - 'A' + 1);
	return num;
}

- mark.ak January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void main()
{
char *p;
int sum=0,l;
clrscr();
printf("enter the string");
gets(p);
l=strlen(p);
while(*p!=NULL)
{
sum=sum+(pow(26,l-1)*(*p-'A'+1));
p++;
l--;
}
printf("%d",sum);
getch();
}

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

1. This is simple base 26 system with little modifications
2. values for A...Z are 1..26
3. Now for next AA this will be (getValue(A)*26^1 + getValue(A)*26^0)
3. Now for next CA this will be (getValue(C)*26^1 + getValue(A)*26^0)
You can use this formula to get any string value like ABCDD

- Santosh March 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Right way to do this !!!

- AA August 09, 2012 | Flag


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