Amazon Interview Question






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

1) Create a hash table containing month numbers or names as key and their respective no. of days in a month

2) Then find then difference between months of dates (Exceptions december and january)

3) then check if the day field is same in both dates, if yes then x no. of months apart, if not well then subtarct the no.of days from first months no. of days as per hash table and add to no. of days from day field in second date that makes them that much days apart.

- Mandar December 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

your solution is not considering the year.so it will not work

- Anonymous December 21, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Create a comparator for dates (compare year, then month (if needed), then date (if needed)). Return <, > or =.

2. Add one month to date A (new date) and compare with date B.
If both equal then they are month apart.
If 'new date' is more than date B then less than month apart.
If 'new date' less than date B then more than month apart.

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

following is the complete code:

note: the dates need to be entered in chronological order

#include<iostream.h>
#include<conio.h>

struct dates
{int dd;
int mm;
int yyyy;
}d1,d2;

void check(int x,int y)
{if(x>y)
cout<<"more than a month apart";
if(x<y)
cout<<"less than a month apart";
}

void main()
{clrscr();
cin>>d1.dd>>d1.mm>>d1.yyyy;
cin>>d2.dd>>d2.mm>>d2.yyyy;

if(d1.yyyy==d2.yyyy)
if(d2.mm==((d1.mm)+1))
if(d2.dd==d1.dd)
cout<<"month apart";
else check(d2.dd,d1.dd);
else check(d2.mm,d1.mm);
else cout<<"more than a month apart";

getch();
}

- neha December 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@neha
if the dates are like 15-12-2009 and 15-01-2010, how do you check with the above code.

- valli January 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we should not consider days.
1. Get month and year of first. - format YYYYMM
2. Get month and year of second. -- YYYYMM
3. if first > second
check month of second, if 12, make it 01 and add 1 to the year
if first < second
check month of first, if 12, make it 01 and add 1 to the year
4. Subtract first - second
If 0 = months apart

- Anonymous January 08, 2010 | 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