Amazon Interview Question for Software Engineer / Developers


Team: General
Country: United States
Interview Type: In-Person




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

why not use sprintf(s,"%d",num);

- Saurya November 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

<pre lang="" line="1" title="CodeMonkey48221" class="run-this">public class IntegerToString
{
public static void main(String[] args)
{
int integer = -987654321;
toString(integer, 10);
}

private static void toString(int integer, int radix)
{
StringBuilder string = new StringBuilder();
boolean isNegative = (integer < 0);
integer = Math.abs(integer);

double length = Math.log(integer) / Math.log(radix);
for (int i = 0; i < length; i++)
{
string.append(integer % radix);
integer /= radix;
}
if (isNegative)
string.append("-");
System.out.println(string.reverse());
}
}</pre><pre title="CodeMonkey48221" input="yes">
</pre>

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

... of course the for loop and the logarithms could be replaced by a do {} while (integer != 0) also

- paPus November 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

string.append (integer % radix) will reverse the number.
Should be string.insert (0, integer % radix)

- Raj November 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Here is one good implementation,

puddleofriddles.blogspot.com/2012/01/implement-itoa.html

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

#include<iostream>
using namespace std;
void reverseString(char a[], int lowIndex, int highIndex)
{
	if(lowIndex == highIndex)
		return;
	while(lowIndex < highIndex)
	{
		char tmp = a[lowIndex];
		a[lowIndex] = a[highIndex];
		a[highIndex] = tmp;
		lowIndex++;
		highIndex--;
	}
}
char* intergerToString(int n)
{
	static char a[1024]; 
	int tmp;
	int i = 0;
	if(n < 0)
		tmp = -n;
	else
		tmp = n;
	if(tmp == 0)
	{
		a[0] = '0';
		a[1] = '\0';
		return a;
	}
	else
	{
		if(n < 0)
			a[i++] = '-';
		while(tmp > 0)
		{
			
			a[i++] = tmp % 10 + '0';
			tmp /= 10;
			
		}
		i--;
		if(a[0] == '-')
			reverseString(a, 1, i);
		else
			reverseString(a, 0, i);
	}
	a[i + 1] = '\0';
	return a;
}
void printString(char *a)
{
	
	while(*a != '\0')
	{
		cout<<*a;
		a++;
	}
	cout<<endl;
}

int main()
{
	char *a = intergerToString(-12345);
	printString(a);
}

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

What are the various parameters involved in the printing of Polarized Hidden Image Technology.

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

char * StringToint(int n,char *arr)
{
if(n==0)
{
return NULL;
}
int i=0;
StringToint(n/2);
arr[i]=(n%10)+'0';
i++;
}

return arr;

}

- atul.87friend November 24, 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