Groupon Interview Question for Software Engineer / Developers Developer Program Engineers


Country: India
Interview Type: Written Test




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

public int atoi( string str)

{
char[] c1= str.ToChar();
len= str.length();
int i=0;num=0;Bool isneg= false;

if (len==0)

Console.Writeline(" empty string");

if (c1[0]=='-')

{ isneg= True;
i=1;
}



while( i<len)
{

num=num*10;
num=num+(c1[i]-'0')
i++;
}

if (isneg==true)
{

return( num*-1);

else
return num;
}

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

correction to the above code:

The individual chars of the string can be directly accessed str[0]...Tochar conversion is not required.

Also i would check

if (str[i] <'0'!! str[i] >9)
console.writeline(" invalid input");

- Anonymous November 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

crackprogramming.blogspot.com/2012/10/implement-atof.html

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

long atoi(char* ip)
{
char* ptr = NULL;
long value = 0;
ptr = ip;
while(ptr)
ptr++;
ptr--;
while(ptr !=(ip -1))
{
if(isDigit(*ptr))
{
value = value + 10*(*ptr - '0');
ptr--;
}
else
break;
}
if((ptr !=(ip -1))&&(*ptr =='-'))
{
value = value*(-1);
}
return value;
}

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

int atoi(char* str)
{
    int ans=0,i=0;

    if(str[i] == '-')
        i += 1;

    for(; str[i] != '\0'; i++)
    {
        ans = (ans<<3) + (ans<<1) + (str[i]-'0');
    }
    if(str[0] == '-')
        ans *= -1;
    return ans;
}

- AK December 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
int i=0;
char *str = "1234";
char *ptr = str;
while(*ptr)
ptr++;
ptr--;
int val=0,sum = 1;
while(ptr != str-1)
{
val = val+sum*(*ptr-'0');
sum = sum*10;
ptr--;
printf("\t%d",val);
}
printf("\n%d",val);
getch();
return 0;
}

- Ajith kumar August 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Test cases:
Negative number
Zero
Positive number
Number greater than int -> Depends whether exception or max number
Null string
Empty string
Decimal
Alpha numeric - starting with alphabet -> Define expected output
Alpha numeric - ending with alphabet -> Define exception or till numeric input
Length of string number is greater than what an int can store

output -> Positive or negative number

Functional test cases:
Where is the function going to be used.
Any memory restrictions>
Any performance restrictions based on the number of times this is called

- Test plan May 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Great book: Elements-Programming-Interviews by Adnan-Aziz

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

How can I get this book?

- Anonymous January 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

This is homework people. Please do not reply.

- dr.house November 05, 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