Amazon Interview Question for Software Engineer / Developers






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

we need to parse the string in the reverse order and iterate from all the characters and subtract 48 from each character and build the required number.

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

???

sysout(Integer.parseInt(str);

- Zaphod August 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry I didn't mention in question but without using java library functions.

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

I dont know if you meant we should also avoid the Math and the String library functions -

String x = "121";
		int res= 0;
		for(int i=0;i<x.length();++i){
			int y = (int)(x.charAt(i)-'0');
			res= (res*10)+y;
		}

- Aathif August 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int main()
{
char a[10]="1234";
int i,num=0;
for(i=0;i<strlen(a);i++)
{
num=num*10+(a[i]-'0');
}
return num;
}

- priyanka August 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int conv(char *a)
{int num=0;
int ten=1;
for(int i=strlen(a)-1;i>=0;i--,ten*=10)//go from last digit
{
num+=(a[i]-'0')*ten;
}
return num;
}

- Kapilan August 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="java" line="1" title="CodeMonkey13178" class="run-this">import java.util.*;
import java.lang.*;

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
System.out.print("Hello World");
}
}
</pre><pre title="CodeMonkey13178" input="yes">
</pre>

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

As an interviewer, I would be very happy if the candidate would ask stuff like:
- can I be sure the input is valid?
- should I handle negative numbers as well?

These are not complicated changes to the algorithm, and they show 'wide' thinking of the candidate

- Ran September 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How do we handle negative numbers?

- Newbie November 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

To handle the negative number, we need to check in the code for ascii value of '-'.

- Milind May 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

it is atoi() function implementation.

- chukka.swathi January 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int y = (int)(x.charAt(i)-'0');
Can some one tell me what is actually going on here??
Why to do char-'0'

- Anonymous February 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(int)x.charAt(i) gives the ascii value of the character.

so if you have 1 at charAt(0), the output is 49. ascii value of 0 is 48. So if we do ascii of 1 - ascii of 0, then we are doing 49 - 48 and the end result is saved in int y which will be 1. Applies same on any number.

- Milind May 10, 2011 | 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