Expedia Interview Question for Software Engineer in Tests


Country: United States




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

/*The code is as follows*/
int size(int n)
{
int c=1;
if(n/10!=0)
{
n=n/10;
c=c+1;
}
return c;
}
void main()
{
int n,i,l,k;
cin>>n;
m=size(n);
for(i=0;i<m;i++)
{
if(n%10!=0)
{
k=n%10;
n=n/10;
l=n-2k;
if(l%7==0)
{
cout<<"divisible";
break;
}
else
{
cout<<"Not Divisible";
break;
}
}
else
{
if(n>=0)
{
n=n/10;
}
else
{
cout<<"Not divisible";
break;
}
}

- RUSHIT PARIKH September 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Errr... wouldn't this do the job?

(num%7)?0:1

If number is 7's multiple then num%7=0, if so we should output 1 (true, number is multiple of 7) if not it should be false.

- amoghavs September 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is there any bit pattern based solution. like 'divisible by 2' problem ?

- bluesky September 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Convert the number to its octal notation, and sum up the digits. The sum is multiple of 7 if and only if the original number is.

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

Remove the last digit of the number, double that digit and subtract from the remainder. Continue this till left with one digit. If that digit is 7/-7/0, you have a winner.

e.g.
14
Remove 4 and double it i.e. 8
Subtract 8 from 1, we get -7 which is awesome.

35 => 3-10 = -7
154 => 15 - 8 = 7
147 => 14-14 = 0

- Adi September 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You could subtract 7 in a loop until the number reaches either 0 or <1. If it reaches 0 then it is multiple of 7, else not divisible.

- Alice7 November 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A number of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit from the number formed by the remaining digits. Continue to do this until a number known to be divisible by 7 is obtained. The original number is divisible by 7 if and only if the number obtained using this procedure is divisible by 7. For example, the number 371: 37 − (2×1) = 37 − 2 = 35; 3 − (2 × 5) = 3 − 10 = −7; thus, since −7 is divisible by 7, 371 is divisible by 7.

Reference : en.wikipedia.org/wiki/Divisibility_rule#Divisibility_by_7

- Neha March 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.


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