Amazon Interview Question for Software Engineer / Developers






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

Simply convert 'n' to a base-26 number. Each digit maps to a letter.

void f(int n)
{
if(n == 0)
return;
f((n-1)/26);
printf("%c", ((n-1)%26+'A'));
}

- Johnny April 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

temp=temp1=n;
while(temp>0) // Find no of characters string will contain
{
no_of_char++;
temp=temp-pow(26,no_of_char);
}
str = (char *)malloc(no_of_char+1);// Dynanically Allocate the buffer

while(temp1>0)
{
temp= temp1 %26; // To find no with respect to alphabet
if(temp!=0)
str[next_char_index++]=temp+65-1;
else
{ // When modulas = 0 we know it is Z(since 26)
str[next_char_index++]='Z';
temp1--;
}
temp1= temp1/(26); // divide by 26 for next pass
}
str[next_char_index]='\0'; // Terminate string with NULL character
strrev(str); // since the characters are stored in reverse manner

- dmelloleslie March 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you post the questing elaborately?
What are the things that we need to find out.

- rider March 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Question is now corrected.

- dmelloleslie March 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>

int main(){
int rownum = 2842 ;
int i = rownum ;
int j = i ;
int count = 0 ;
int power = 0 ;

while(i >=26){
j = i ;
count = 0 ;
power = 1 ;
while(j >=26){
count++ ;
j = j/26 ;
}
printf("%c", 'A'+ j - 1) ;

for(j = 1 ; j <= count; j++){
power = power*26 ;
}
i = (i % power) ;
}
printf("%c\n", ('A' + i)) ;

return 0 ;
}

- Anonymous July 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void printSeries(int n) {
		int qt = n / 26;
		qt--;
		int rem = n % 26;
		rem--;
		char[] alpha = new char[26];
		char a = 'A';

		for (int i = 0; i < 26; i++) {
			alpha[i] = (char) a;
			a++;
		}

		String out = "";

		if (rem == -1) {
			qt--;
			rem = 25;
		}

		if (qt >= 0) {
			out = out + alpha[qt];
		}

		if (rem >= 0) {
			out = out + alpha[rem];
		}

		System.out.println(qt + " " + rem);
		System.out.println(out);
	}

- sl714 September 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{def convertToTitle(num):
"""
:type n: int
:rtype: str
"""
result = ''
while num:
result = chr(ord('A') + (num-1)%26) + result
num = (num - 1)/26
return result

num= 29
convertToTitle(num)
output : AC}}

- Shab June 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python Solution

def convertToTitle(num):
    """
    :type n: int
    :rtype: str
    """
    result = ''
    while num:
        result = chr(ord('A')  + (num-1)%26) + result
        num = (num - 1)/26
    return result
    
num= 29
convertToTitle(num)

Output : AC

- Shab June 11, 2016 | 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