## 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+"";
}

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;
}``````

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;
}

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;
}``````

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);
}
}

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;
}``````

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;``````

}

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;
}

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;
}``````

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();
}``````

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;
}``````

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.

### 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.