Amazon Interview Question for Software Engineer / Developers






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

boot function DateWithOneMonthApart (date1, date2)
{
   dayOfMonth1 = /*seperate day From date1 */
   dayOfMonth2 = /*seperate day From date2 */
   MonthOfDate1 = /*seperate Month From date1 */
   MonthOfDate2 = /*seperate Month From date2 */
   YearOfDate1 = /*seperate Year From date1 */
   YearOfDate2 = /*seperate Year From date2 */

   if (dayOfMonth1 != dayOfMonth2)
      return False;

   PrevMonthOfDate2 = MonthOfDate2 - 1; 
   
   if (PrevMonthOfDate2 == 0) 
   {
      PrevMonthOfDate2 = 12;
      PrevYearOfDate2 = YearOfDate2-1:
   }


   NextMonthOfDate2 = MonthOfDate2 - 1;
   if (NextMonthOfDate2 == 13)
   {
      NextMonthOfDate2 = 1;
      NextYearOfDate2 = YearOfDate2+1:
   }

   if ((PrevYearOfDate2 == YearOfDate1 && PrevMonthOfDate2 == MonthOfDate1) ||
       (NextYearOfDate2 == YearOfDate1 && NextMonthOfDate2 == MonthOfDate1) )
    return true;

  return false
}

- ss June 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Very simple and nice solution. Easy to understand.

- SS June 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong answer.. consider feb28 and mar31

- swathi June 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

in which format we are getting these dates? string? java.util.Date?

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

<pre lang="" line="1" title="CodeMonkey93011" class="run-this">struct Date
{
int dd;
int mon;
int year;
};
int convert(char* mon);
int compMonDiff(Date& dt1, Date& dt2);

int main()
{
Date dt1,dt2;
cout<<"Enter date 1 ";
char mon[4];
cin>>mon>>dt1.dd>>dt1.year;
dt1.mon = convert(mon);
cout<<"Enter date 2 ";
cin>>mon>>dt2.dd>>dt2.year;
dt2.mon = convert(mon);
switch(compMonDiff(dt1,dt2))
{
case 0:
cout<<"Less than One month apart\n";
break;
case 1:
cout<<"One month apart\n";
break;
case 2:
cout<<"More than one month apart\n";
break;
}

}
int compMonDiff(Date& dt1, Date& dt2)
{
int diff = 12*(dt2.year - dt1.year);
diff += dt2.mon - dt1.mon;
if(diff == 0)
return 0;
else if(diff > 1)
return 2;
else
{
if(dt1.dd == dt2.dd)
return 1;
else if(dt2.dd < dt1.dd)
return 0;
else return 2;
}
}
int convert(char* mon)
{
if(!strcmp(mon,"Jan"))
return 1;
if(!strcmp(mon,"Feb"))
return 2;
if(!strcmp(mon,"Mar"))
return 3;
if(!strcmp(mon,"Apr"))
return 4;
if(!strcmp(mon,"May"))
return 5;
if(!strcmp(mon,"Jun"))
return 6;
if(!strcmp(mon,"Jul"))
return 7;
if(!strcmp(mon,"Aug"))
return 8;
if(!strcmp(mon,"Sep"))
return 9;
if(!strcmp(mon,"Oct"))
return 10;
if(!strcmp(mon,"Nov"))
return 11;
if(!strcmp(mon,"Dec"))
return 12;
}</pre><pre title="CodeMonkey93011" input="yes">
</pre>

- Anonymous June 17, 2011 | 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