Expedia Interview Question for Software Engineer / Developers






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

char* s="-99909zsddfasd";
int num=0,flag=0;
for(int i=0;i<=strlen(s);i++)
{
if(s[i] >= '0' && s[i] <= '9')
num = num * 10 + s[i] -'0';

else if(s[0] == '-' && i==0)
flag =1;
else

break;


}
if(flag == 1)
num = num * -1;
printf("%d",num);

- ST May 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

given the ascii char,get the ascii value of it and subtract 48 from it to get its integer value. This is because integers start from 48-57.

for example given ascii char '5',convert to int?
ascii val of char '5' is 53. subtracting 48 from it gives its integer value 5

- Anonymous October 02, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>
main(){
char c[10] ="6786756\0";
int size = strlen(c);
int i=0;
int count=0;
while(size--){
i *=10;
i+= c[count++]-48;
}
printf("%d",i);
}

- Anonymous February 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

void my_atoi(char str[], int& output)
{
int res = 0;

int i = 0;
int length = strlen(str);

bool is_negative = false;
while (i < length)
{
if (str[i] == ' ')
{
++i;
continue;
}

if (str[i] == '-')
{
++i;
is_negative = true;
}

break;
}

int j = length - 1;
while (j > 0)
{
if (str[j] == ' ')
{
--length;
--j;
}
else
break;
}

while (i < length)
{
if (str[i] <= '9' && str[i] >= '0')
{
int temp_res;
temp_res = res * 10 + str[i] - '0';
if ((temp_res + '0' - str[i]) / 10 != res)
{
std::cout << "Overflow!";
break;
}
else
{
res = temp_res;
}
}
else
{
std::cout << "Invalid input!";
break;
}
++i;
}

if (is_negative)
output = -1 * res;
else
output = res;
}

int main()
{
int res;
my_atoi(" -345 ", res);

return 0;
}

- hao.liu0708 November 26, 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