Interview Question






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

void printstring(int num)
{
if(!num)
return ;
int rem=0;
rem=num%26;
num=num/26;
printstring(num);
printf("%c",96+rem);

}

- Anonymous May 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Another moron who doesn't test his code.

- Anonymous May 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The solution for this problem involves us thinking in terms of Base 26 notation like Hexadecimal (which is 16). I am trying to remember the way we convert Base 16 to Base 10. We could apply the similar logic.

After writing I kind of remember trying to get the modulo of the number any may be first solution leads to that.

- prolific.coder May 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void base26(int n)
{
if(n<base) {
putchar('a'+n%26-1);
return;
}
base26(n/26);
putchar('a'+n%26-1);
}

- buried.shopno May 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I find no difference bet ur code n anonymous'.Still his code is more readable

- Hawk May 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Who is this moron - who comments but does not provide any answers.

1. one issue i can see is negative number check .

- bigdog May 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

#Since you asked so nicely...
#

def convert(n):
  assert isinstance(n, int) and n >= 0
  d = 1
  while d <= n:
    n -= d
    d *= 26
  chars = []
  while True:
    d //= 26
    if d == 0:
      break
    x, n = divmod(n, d)
    chars.append(x)
  return ''.join(chr(ord('a') + x) for x in chars)
#

- Anonymous May 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Did you imply negative numbers

- Anonymous May 22, 2010 | 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