Amazon Interview Question for Software Engineer / Developers


Team: Kindle
Country: India
Interview Type: In-Person




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

float num = 24.3;
char ch[MAX_SIZE];
sprintf(ch,"%f",num);

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

what the question means?

- Krishna Sai Mulpuri July 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you cann't use sprintf and MAX_SIZE is also not allowed. Mem allocation should be same as length of float. e.g. "24.356" mem allocation should be 6 bytes.

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

stringstream ss (stringstream::in | stringstream::out);

ss << val;

string test = ss.str();

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

// this shud work :

void ftoa(float num, char *str)
{
  int intpart = num;
  int intdecimal;
  int i;
  float decimal_part;
  char decimal[20];

  memset(str, 0x0, 20);
  itoa(num, str, 10);

  strcat(str, ".");

  decimal_part = num - intpart;
  intdecimal = decimal_part * 1000000;

  if(intdecimal < 0)
  {
    intdecimal = -intdecimal;
  }
  itoa(intdecimal, decimal, 10);
  for(i =0;i < (PRECISION - strlen(decimal));i++)
  {
    strcat(str, "0");
  }
  strcat(str, decimal);
}

- singhsourabh90 July 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@singhsourabh90:can u explain the algo.

- Ani July 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

float f;
int k,count=0,i=0;
char s[20];
scanf("%f",&f);
k=(int)f;
while(f-k!=0.0)
{
f=f*10;
k1=(int)f;
count++;
}

//now f is in integer format and now decimal can be placed using count
while(f>0)
{
if(count!=0)
{
s[i]=(f%10)+48;
f=f/10;
}
else
{
s[i]='.';
}
i++;
count--;
}
//reversing the above string gives the desired result....
Pls comment on this code.

- Ani July 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

% can't be used on float. so given code won't compile .

- singhsourabh90 July 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define PRECESION 10000000

int _tmain(int argc, _TCHAR* argv[])
{
float input = -12340.004321;
char itamap[10] = {'0','1','2','3','4','5','6','7','8','9'};
char val[20] = {0};

float tempdecimal, value;
int intpart;
int index = 0;

value = input;
if(value < 0) // handle -ve
{
val[index++] = '-';
value *= -1;
}
else
val[index++] = '+';

intpart = value;
tempdecimal = value - intpart;

if(intpart == 0)
{
val[index++] = itamap[intpart];
}
while(intpart)
{
val[index++] = itamap[ intpart%10];
intpart /= 10;
}
val[index] = '.';
int i = 1 , j = index-1;
for(i; i <index/2; i++,j--)
{
char temp = val[i];
val[i] = val[j];
val[j] = temp;
}
index++;
int decimalIndex = 10;
i = 10;
while(decimalIndex*i < PRECESION)
{
tempdecimal *= decimalIndex;
intpart = tempdecimal;
tempdecimal -= intpart;
val[index++] = itamap[intpart];

i *= 10;
}
printf("%s",val);
return 0;
}

- Deb July 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
void ftoa(float a,char s[])
{ float b=a;
int c;
if(b<0)
{
a=-a;
}
i=0;
c=(int)a;
float d1=a-c;

if(d1>0)
{
int count=0;
while(d1<1)
{
d1*10;count++;
}
}
do{
s[i++]=n%10+'0';}
s[i++]='.'
int n=(int )d1;
do{
s[i++]=n%10+'0';}
s[i++]='.'
while((n/=10)>0);
int n=c;
do{
s[i++]=n%10+'0';}
s[i++]='.'
while((n/=10)>0);
if(b<0)
s[i++]='-';
s[i]='\0'
reverse(s);
}

- Anonymous July 31, 2012 | 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