Amazon Interview Question for Software Engineer in Tests


Country: United States
Interview Type: Phone Interview




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

public String convert(Integer value){
return value+"";
}

- Chaitanya Srikaolapu November 18, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

stack<int> getDigits(int b)
{
	stack<int> digits;
	int x, digit;
	int a = b;
	while (a > 10)
	{
		x = (a / 10);
		digit = a - (x * 10);
		digits.push(digit);
		a = x;
	}
	digits.push(a);
	return digits;
}

//int StringToNum(string s)
//{
//
//}


string NumToString(int a)
{
	string s;
	stack<int> digits = getDigits(a);
	int size = digits.size();
	for (int i = 0; i < size; i++)
	{
		int num = digits.top();
		s.push_back(num +48);
		digits.pop();
	}
	return s;
}

- Krishna Kumaran November 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

using namespace std;

char int_to_char[10] = { '0','1', '2', '3', '4', '5', '6', '7', '8', '9' };

char* toString(int i){
if (i == 0){
char* c = new char[1];
*c = '0';
return c;
}
char* r;
int absolute = i;
if (i < 0){
absolute = -1 * absolute;
}
int len = 0;
while(absolute > 0){
len++;
absolute = absolute/10;
}

absolute = i;
if (i < 0){
absolute = -1 * absolute;
len++;
}

r = new char[len];

while(absolute > 0){
r[--len] = int_to_char[absolute % 10];
absolute = absolute/10;
}
if (i < 0){
r[--len] = '-';
}
return r;
}

int main()
{
cout << toString(-100);
// handle delete of allocations
return 0;
}

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

#include <iostream>

using namespace std;

char int_to_char[10] = { '0','1', '2', '3', '4', '5', '6', '7', '8', '9' };

char* toString(int i){
    if (i == 0){
        char* c = new char[1];
        *c = '0';
        return c;
    }
    char* r;
    int absolute = i;
    if (i < 0){
        absolute = -1 * absolute;
    }
    int len = 0;
    while(absolute > 0){
        len++;
        absolute = absolute/10;
    }
    
    absolute = i;
    if (i < 0){
        absolute = -1 * absolute;
        len++;
    }
    
    r = new char[len];
    
    while(absolute > 0){
        r[--len] = int_to_char[absolute % 10];
        absolute = absolute/10;
    }
    if (i < 0){
        r[--len] = '-';
    }
    return r;
}

int main()
{
    cout << toString(0);
    // handle delete of allocations
    return 0;
}

- Object November 28, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Stack;

public class TestProgramming {
public static void main(String ar[]) {
int i=2345678;
Stack<Integer> stack = new Stack<Integer>();
while(i>0) {
int curr=i%10;
i=i/10;
stack.push(curr);
}
StringBuilder sbr=new StringBuilder();
while(!stack.isEmpty())
sbr.append(stack.pop());
String str=sbr.substring(0);
System.out.println(str);
}
}

- vitebonus December 03, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String getstringdata(int intvalue){
	
	String str = '"'+String.valueOf(intvalue)+'"';
		
	return str;
}

- prakash December 19, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String getstringdata(int intvalue){
	
	String str = '"'+String.valueOf(intvalue)+'"';
		
	return str;

}

- Prakash December 19, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public String getstringdata(int intvalue){

String str = '"'+String.valueOf(intvalue)+'"';

return str;
}

- Prakash December 19, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char* numToString(int num)
{
    static char output[32]={0,};
    static char reverse[32]={0,};
    int n = num, idx = 0;
    
    while(n)
    {
        output[idx] = 48 + (n%10);
        
        idx++;
        n = n/10;
    }
    output[idx]='\0';
    
    int len = idx;
    //reverse the string 
    idx = 0;
    printf("\n reversed string = ");
    while(idx != len)
    {
        reverse[idx] = output[len-idx-1];
        printf("%c", reverse[idx]);
        idx++;
    }
    reverse[idx]='\0';
    
    return reverse;
}

- vineet.iitd February 26, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private String numberToString(int number) {
        StringBuilder sb = new StringBuilder();
        int zero= '0';
        while(number != 0){
            sb.insert(0, (char) (zero + (number%10)));
            number = number/10;
        }
        return sb.toString();
    }

- Sunil Vakotar April 12, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string func(int num)
{
	int i,j,n;
	bool nega = false;
	string str = "";
	if(num < 0)
	{
		nega = true;
		num = num * (-1);	
	}
	while(num)
	{
		str.push_back('0' + num % 10);
		num = num / 10;	
	}
	if(nega)
	{
		str.push_back('-');
	}
	reverse(str.begin(),str.end());
	return str;
}

- sushocoder September 13, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def int_to_string(num):
is_negative = False

if num < 0:
is_negative = True
num = -num

result = ""
while num > 0:
digit = num % 10
result = chr(ord('0') + digit) + result
num //= 10

if is_negative:
result = "-" + result

return result or "0"

- malsawi.airwatch July 24, 2023 | 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