Epic Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int NUMBEROFDAYS[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

bool isLeapYear(int year)
{
    return (year%400 == 0)||(year%4 == 0 && year%100 != 0);
}

int numberOfDaysInMonthAndYear(int month, int year)
{
    if(isLeapYear(year) && month == 2)
    {
        return 29;
    }
    else return NUMBEROFDAYS[month];
}

void printDay(int day, int month, int year, int whichDay)
{
    cout<<day<<", "<<month<<", "<<year<<" is "<<whichDay<<endl;
}

void findWeek(int day, int month, int year, int whichDay)
{
    for( int i = whichDay ; i > 0 ; -- i )
    {
        if(day == 1)
        {
            if(month == 1)
            {
                year--;
                month = 12;
                day = numberOfDaysInMonthAndYear(month, year);
            }
            else month--;
        }
        else day--;
    }
    
    for(int i = 0; i < 7 ; ++ i)
    {
        printDay(day, month, year, i);
        day++;
        if(day > numberOfDaysInMonthAndYear(month, year) )
        {
            day = 1;
            month++;
            if(month > 12)
            {
                month = 1;
                year++;
            }
        }
    }
    
}


int main (int argc, const char * argv[])
{
    findWeek(1,1,2001,3);
    return 0;
}

- Anonymous February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Add this line to the else part of the if(day == 1) to make it work for the inputs with 2 3 2001 3 :

else {
	            	month--;
	            	day = numberOfDaysInMonthAndYear(month, year);
	            }

- careercupuser May 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

import java.io.*;
import java.util.*;
import java.text.*;

public class week {
public static void main (String[] args) {
String dt = "09/13/2012";
printWeek(dt);
}
static void printWeek(String str) {
SimpleDateFormat ft = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat sft = new SimpleDateFormat("E MM/dd/yyyy");
try {
Date date = ft.parse(str);
Calendar cal = new GregorianCalendar();
cal.setTime(date);
int temp = cal.get(cal.DAY_OF_WEEK);
while (temp > 0) {
cal.add(Calendar.DATE, -1);
temp--;
}
while (temp < 7) {
cal.add(Calendar.DATE, 1);
System.out.println(sft.format(cal.getTime()));
temp++;
}
} catch(ParseException e) {
System.out.println("Unparsable");
}

}

}

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

<pre lang="" line="1" title="CodeMonkey21243" class="run-this"> public static void main(String[] args) {

String weekNm[]={"Sunday","Monday","Tues","wed","thurs","fri","sat"};
int weekDayInNum[]={0,1,2,3,4,5,6};

Calendar cal=Calendar.getInstance();
// Set the date .. can take user input and then parse it to these values
cal.set(Calendar.YEAR, 2012);
cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DAY_OF_MONTH, 31);

int monthsDays[]={31,28,31,30,31,30,31,31,30,31,30,31};
String nameOfMonths[]={"Jan","feb","Mar","Apr","May","June","july","Aug","Sept","Oct","Nov"
,"dec"};
if((year % 400 == 0 ||(year % 4 == 0 && year % 100 != 0)))
monthsDays[1]=29;


int j=0;
int i=0;
int domNew=dom;
int indexOfMonth=month;
String datesOfWeek[]=new String[7];
for( i=dow-1;i<(weekDayInNum.length);i++)
{


if((domNew)%monthsDays[indexOfMonth]!=0)
datesOfWeek[i]=""+(domNew)%monthsDays[indexOfMonth];
else
datesOfWeek[i]=""+monthsDays[indexOfMonth];
domNew++;
}

for(j=dow-2;j>=0;j--)
{

datesOfWeek[j]=""+dom;
}

for(int k=0;k<datesOfWeek.length;k++)
{
System.out.println(" "+datesOfWeek[k]+" "+weekNm[k]);
}

}

}
</pre><pre title="CodeMonkey21243" input="yes">
</pre>

- Anonymous December 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

These steps are also added to get those values.

int month = cal.get(Calendar.MONTH) ;
int year = cal.get(Calendar.YEAR);
int dow = cal.get(Calendar.DAY_OF_WEEK); // if value is 2 which means monday
int dom = cal.get(Calendar.DAY_OF_MONTH);

- Anonymous December 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry friends..

pls add few more conditions in place of for loop with j as counter. It should be complete then even if the date is 1st of any month . it will fetch dates fro previous months. Thanks.



for(j=dow-2;j>=0;j--)
{
--dom;
if(dom<0)
{
datesOfWeek[j]=""+(int)((int)monthsDays[indexOfMonth-1]+(int)dom);
}
else if(dom==0)
{
datesOfWeek[j]=""+monthsDays[indexOfMonth-1];
}
else
{
datesOfWeek[j]=""+dom;
}
}

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

Hey do we get an integrated development environment for writing code in assessment exam?

- robby December 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you use Calendar class you need only 4 lines of actual code to get the day of week

- deb December 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isLeapYear(int year)
{
  returns true if it's a leap year else false
}

enum Day {1="monday",2="tuesday",3="wednesday"...};

struct Date{
	int date;
	int month;
	int year;
	Day day;
}currdate;

Date tempdate;

for(int i=0;i<currdate.day;i++)
{
SET tempdate variables as the following:
currdate.day+i
(currdate.date+i)%31 if currdate.month=1,3,5,7,8,10,12
(currdate.date+i)%30 if currdate.month=4,6,9,11
(currdate.date+i)%28 if currdate.month=2 && !isLeapYear(currdate.year)
(currdate.date+i)%29 if currdate.month=2 && isLeapYear(currdate.year) 
(currdate.month+i) if currdate.month=1,3,5,7,8,10,12 date crosses 31
(currdate.month+i) if currdate.month= 4,6,9,11 && date crosses 30
(currdate.month+i) if currdate.month=2 && !isLeapYear(currdate.year) && date crosses 28
(currdate.month+i) if currdate.month=2 && isLeapYear(currdate.year) && date crosses 29
currdate.year+i if currdate.month==12 and currdate.date crosses 31
}
for(i=0;i<7-currdate.day;i++)
{
SET tempdate variables as the following:
currdate.day+i
(currdate.date+i)%31 if currdate.month=1,3,5,7,8,10,12
(currdate.date+i)%30 if currdate.month=4,6,9,11
(currdate.date+i)%28 if currdate.month=2 && !isLeapYear(currdate.year)
(currdate.date+i)%29 if currdate.month=2 && isLeapYear(currdate.year) 
(currdate.month+i) if currdate.month=1,3,5,7,8,10,12 date crosses 31
(currdate.month+i) if currdate.month= 4,6,9,11 && date crosses 30
(currdate.month+i) if currdate.month=2 && !isLeapYear(currdate.year) && date crosses 28
(currdate.month+i) if currdate.month=2 && isLeapYear(currdate.year) && date crosses 29
currdate.year+i if currdate.month==12 and currdate.date crosses 31
}

- code_monkey January 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool has_leaped = (year % 4 == 0) && month >= 3;
int day_of_week = (day_of_month + month_correction[month] + year + (year-1)%4 + (has_leaped ? 1 : 0) ) % 7;

The day of the week advances one when the day advances one; it advances some pre-calculated amount when the month advances one (so use a pre-calculated array for this value); it advances one when the year increases (because 365%7 == 1), and an additional one on leap years. Leap years are years that are either divisionable by 4 but not by 100, or divisionable by 400. See wikipedia for more details: "Leap Year" or "Weekday Determination"

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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int NUMBEROFDAYS[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

bool isLeapYear(int year)
{
    return (year%400 == 0)||(year%4 == 0 && year%100 != 0);
}

int numberOfDaysInMonthAndYear(int month, int year)
{
    if(isLeapYear(year) && month == 2)
    {
        return 29;
    }
    else return NUMBEROFDAYS[month];
}

void printDay(int day, int month, int year, int whichDay)
{
    cout<<day<<", "<<month<<", "<<year<<" is "<<whichDay<<endl;
}

void findWeek(int day, int month, int year, int whichDay)
{
    for( int i = whichDay ; i > 0 ; -- i )
    {
        if(day == 1)
        {
            if(month == 1)
            {
                year--;
                month = 12;
                day = numberOfDaysInMonthAndYear(month, year);
            }
            else month--;
        }
        else day--;
    }
    
    for(int i = 0; i < 7 ; ++ i)
    {
        printDay(day, month, year, i);
        day++;
        if(day > numberOfDaysInMonthAndYear(month, year) )
        {
            day = 1;
            month++;
            if(month > 12)
            {
                month = 1;
                year++;
            }
        }
    }
    
}


int main (int argc, const char * argv[])
{
    findWeek(1,1,2001,3);
    return 0;
}

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

and }#include <iostream>
#include <vector>
#include <string>

using namespace std;

void week_day(int day, int month, int year);
bool is_leap(int year);
void up_date(int *day, int *month, int *year, int *week_day);
void down_date(int *day, int *month, int *year);
int num_days(int month, int year);



int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string dayOfWeek[7] = {"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};


int f_day = 1, f_month = 1, f_year = 1970, f_week_day = 4;

int main(){

        week_day(1, 6, 2012);

        return 0;
}


void week_day(int day, int month, int year){

        int n_day = f_day, n_month = f_month, n_year = f_year, n_week_day = f_week_day;


        while(day != n_day || month != n_month || year != n_year){

                //cout<<n_day<<"/"<<n_month<<"/"<<n_year<<"/"<<n_week_day<<endl;
                up_date(&n_day, &n_month, &n_year, &n_week_day);
        }

        cout<<dayOfWeek[n_week_day]<<endl;


}

bool is_leap(int year){

        if(year%400 == 0 || year%4 == 0)
                return true;

        if(year%100 == 0)
                return false;
        return false;

}


void up_date(int *day, int *month, int *year, int *week_day){

        if((*day+1) > num_days(*month, *year)){

                if((*month+1) < 12){
                        (*month)++;
                        *day = 1;

                }
                else{//if it is the last day of the year
                        *month = 1;
                        *day = 1;
                        (*year)++;

                }


        }
        else{//if it is not the end of the month just increase the day
                (*day)++;

        }

        if(*week_day < 6)
                (*week_day)++;
        else
                *week_day = 0;


}


int num_days(int month, int year){

        if((month-1) < 0 || (month-1) > 11){
                cout<<"Invalid month"<<endl;
                return -1;
        }
        if((month-1) == 1 && is_leap(year))
                return daysInMonth[month-1]+1;


        return daysInMonth[month-1];

- mbaise June 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class FindWeekDates {
	public static void main(String args[]) throws IOException
	{
		GregorianCalendar g= new GregorianCalendar();
		InputStreamReader ir = new InputStreamReader(System.in);
		BufferedReader br=new BufferedReader(ir);
		System.out.println("Enter the date");
		String d=br.readLine();
		System.out.println("Enter the month with value 0-Jan and so on");
		String mon=br.readLine();
		System.out.println("Enter the year");
		String yr=br.readLine();
		
		int dt=Integer.parseInt(d);
		g.set(Calendar.DATE, dt);
		g.set(Calendar.MONTH, Integer.parseInt(mon));
		g.set(Calendar.YEAR, Integer.parseInt(yr));
		
		int day_of_week=g.get(Calendar.DAY_OF_WEEK);
		System.out.println("Day of the week s "+day_of_week+"  for the given date "+g.get(Calendar.DATE)+" "+g.get(Calendar.MONTH));
		
		System.out.println(day_of_week);
	
		int temp=day_of_week;
		while(temp>1)
		{
			g.add(Calendar.DATE, -1);
			System.out.println(g.get(Calendar.DATE)+"   "+g.get(Calendar.MONTH));
			temp--;
		}
		
		//lets reassign the values of the day of the week and also the entered date;
		temp=day_of_week;
		g.set(Calendar.DATE, dt);
		g.set(Calendar.MONTH, Integer.parseInt(mon));
		g.set(Calendar.YEAR, Integer.parseInt(yr));
		System.out.println("temp now s "+temp);
		while(temp<7)
		{
			
			g.add(Calendar.DATE,1);
			
			System.out.println(g.get(Calendar.DATE)+"   "+g.get(Calendar.MONTH));
			
			temp++;
		}
	}
}

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class FindWeekDates {
public static void main(String args[]) throws IOException
{
GregorianCalendar g= new GregorianCalendar();
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("Enter the date");
String d=br.readLine();
System.out.println("Enter the month with value 0-Jan and so on");
String mon=br.readLine();
System.out.println("Enter the year");
String yr=br.readLine();

int dt=Integer.parseInt(d);
g.set(Calendar.DATE, dt);
g.set(Calendar.MONTH, Integer.parseInt(mon));
g.set(Calendar.YEAR, Integer.parseInt(yr));

int day_of_week=g.get(Calendar.DAY_OF_WEEK);
System.out.println("Day of the week s "+day_of_week+" for the given date "+g.get(Calendar.DATE)+" "+g.get(Calendar.MONTH));

System.out.println(day_of_week);

int temp=day_of_week;
while(temp>1)
{
g.add(Calendar.DATE, -1);
System.out.println(g.get(Calendar.DATE)+" "+g.get(Calendar.MONTH));
temp--;
}

//lets reassign the values of the day of the week and also the entered date;
temp=day_of_week;
g.set(Calendar.DATE, dt);
g.set(Calendar.MONTH, Integer.parseInt(mon));
g.set(Calendar.YEAR, Integer.parseInt(yr));
System.out.println("temp now s "+temp);
while(temp<7)
{

g.add(Calendar.DATE,1);

System.out.println(g.get(Calendar.DATE)+" "+g.get(Calendar.MONTH));

temp++;
}
}
}

- Prem June 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class WeekOfDates {

	public static void printDays(String date) {
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
		SimpleDateFormat df = new SimpleDateFormat("E MM/dd/yyyy");
		try {
			Date d = sdf.parse(date);
			Calendar cal = new GregorianCalendar();
			cal.setTime(d);

			int tmp = cal.get(Calendar.DAY_OF_WEEK);
			int tmp1 = tmp;
			while (tmp > 0) {
				System.out.println(df.format(cal.getTime()));
				cal.add(Calendar.DATE, -1);
				tmp--;
			}
			while (tmp <= tmp1) {
				cal.add(Calendar.DATE, 1);
				tmp++;
			}
			while (tmp <= 7) {
				System.out.println(df.format(cal.getTime()));
				cal.add(Calendar.DATE, 1);
				tmp++;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		printDays("02/19/2013");
	}

}

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

import java.io.*; 
import java.util.*; 
import java.text.*; 

public class calend { 
public static void main (String[] args) throws ParseException { 
String dt = "03/13/2013"; 
printWeek(dt); 
} 


static void printWeek(String str) throws ParseException { 
SimpleDateFormat ft = new SimpleDateFormat("MM/dd/yyyy"); 
SimpleDateFormat sft = new SimpleDateFormat("E MM/dd/yyyy"); 

Date date = ft.parse(str);   System.out.println(date); 
Calendar cal = new GregorianCalendar(); 
cal.setTime(date); 
int temp = cal.get(cal.DAY_OF_WEEK); System.out.println(temp); 
while (temp > 0) { 
cal.add(Calendar.DATE, -1); 
temp--; 
} 
while (temp < 7) { 
cal.add(Calendar.DATE, 1); 
System.out.println(sft.format(cal.getTime())); 
temp++; 
} 

} 

}

- disun March 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the examples given in the question for the year 2001 seem to be wrong by day ahead. I checked with online calendars and it does not match with the calendars provided online (i even cross checked it with google calendar). Here is a working C++ code which works without the fault in the question.

#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int dd, mm, yy, i, ans, mon[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    char day[7][10]={ "Friday", "Saturday",  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"};
    cin>>mm>>dd>>yy;
    for (i=1583; i<yy; i++)
    {
        if ((i%4==0 && i%100!=0) || i%400==0)
        {   
            ans+=366;
        }
        else
            ans+=365;
    }
    for (i=0; i<(mm-1); i++)
    {
        ans+=mon[i];
    }
    ans+=dd;
    if (((yy%4==0 && yy%100!=0) || yy%400==0) && mm>2)
    {   
        ans+=1;
    }
    ans=ans%7;
    cout<<day[ans];
    return 0;
}

- Meraj Ahmed November 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why 1583? and is there any typo in this line?

if (((yy%4==0 && yy%100!=0) || yy%400==0) && mm>;2)

- epic January 08, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

qqq

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

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef struct dateStruct {
	int yy;
	int mm;
	int dd;
} date;

int Months[] = {31, 28, 31, 30,
				31, 30, 31, 31,
				30, 31, 30, 31};

string weekDays[] = {
	"Sunday", "Monday", "Tuesday", "Wednesday",
	"Thursday", "Friday", "Saturday"
};

class solution {
private:
	bool isDateLarger (date A, date B) {
		if (A.yy > B.yy)
			return true;
		else if (A.yy < B.yy)
			return false;
		if (A.mm > B.mm)
			return true;
		else if (A.mm < B.mm)
			return false;
		if (A.dd > B.dd)
			return true;
		else if (A.dd < B.dd)
			return false;
		return true;
	}

	bool isLeap(int yy) {
		if (yy % 4 == 0 && yy % 100 != 0)
			return true;
		return false;
	}
	//Default A < B
	int monthDays(int mmA, int mmB, int ddA, int ddB, int yy) {
		int mm, days = 0;
		for (mm = mmA + 1; mm < mmB; mm++) {
			days += Months[mm - 1];
			if (isLeap(yy) && mm == 2)
				days++;
		}
		if (mmA == mmB)
			days = ddB - ddA;
		else {
			days = days + Months[mmA - 1] - ddA;
			if (isLeap(yy) && mmA <= 2)
				days++;
			days = days + ddB;
		}
		//cout << Months[mmA - 1] - ddA << endl;
		//cout << days << endl;
		return days;
	}
	//Default A < B
	int diffDays (date A, date B) {
		int yy;
		int days = 0;
		for (yy = A.yy + 1; yy < B.yy; yy++) {
			if (isLeap(yy))
				days += 366;
			else
				days += 365;
		}
		//cout << days << endl;
		if (A.yy == B.yy)
			days = monthDays(A.mm, B.mm, A.dd, B.dd, A.yy);
		else {
			days += monthDays(A.mm, 12, A.dd, 31, A.yy);
			days += monthDays(1, B.mm, 1, B.dd, B.yy) + 1;
		}
		return days;
	}	
public:
	int findWeek (date findDate, date baseDate, int baseWeek) {
		bool isLarger = isDateLarger(findDate, baseDate);
		int days, weekDay;
		if (isLarger) {
			days = diffDays(baseDate, findDate);
			weekDay = (baseWeek + days) % 7;
		} else {
			days = diffDays(findDate, baseDate);
			weekDay = (baseWeek - (days % 7) + 7) % 7;
		}
		//cout << days << endl;
		return weekDay;
	}
};

int main() {
	solution sol;
	date baseDate;
	baseDate.yy = 2015;
	baseDate.mm = 3;
	baseDate.dd = 16;
	date findDate;
	findDate.yy = 2007;
	findDate.mm = 4;
	findDate.dd = 1;
	int weekday = sol.findWeek(findDate, baseDate, 1);
	cout << weekDays[weekday] << endl;
	return 0;
}

- My Code March 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef struct dateStruct {
	int yy;
	int mm;
	int dd;
} date;

int Months[] = {31, 28, 31, 30,
				31, 30, 31, 31,
				30, 31, 30, 31};

string weekDays[] = {
	"Sunday", "Monday", "Tuesday", "Wednesday",
	"Thursday", "Friday", "Saturday"
};

class solution {
private:
	bool isDateLarger (date A, date B) {
		if (A.yy > B.yy)
			return true;
		else if (A.yy < B.yy)
			return false;
		if (A.mm > B.mm)
			return true;
		else if (A.mm < B.mm)
			return false;
		if (A.dd > B.dd)
			return true;
		else if (A.dd < B.dd)
			return false;
		return true;
	}

	bool isLeap(int yy) {
		if (yy % 4 == 0 && yy % 100 != 0)
			return true;
		return false;
	}
	//Default A < B
	int monthDays(int mmA, int mmB, int ddA, int ddB, int yy) {
		int mm, days = 0;
		for (mm = mmA + 1; mm < mmB; mm++) {
			days += Months[mm - 1];
			if (isLeap(yy) && mm == 2)
				days++;
		}
		if (mmA == mmB)
			days = ddB - ddA;
		else {
			days = days + Months[mmA - 1] - ddA;
			if (isLeap(yy) && mmA <= 2)
				days++;
			days = days + ddB;
		}
		//cout << Months[mmA - 1] - ddA << endl;
		//cout << days << endl;
		return days;
	}
	//Default A < B
	int diffDays (date A, date B) {
		int yy;
		int days = 0;
		for (yy = A.yy + 1; yy < B.yy; yy++) {
			if (isLeap(yy))
				days += 366;
			else
				days += 365;
		}
		//cout << days << endl;
		if (A.yy == B.yy)
			days = monthDays(A.mm, B.mm, A.dd, B.dd, A.yy);
		else {
			days += monthDays(A.mm, 12, A.dd, 31, A.yy);
			days += monthDays(1, B.mm, 1, B.dd, B.yy) + 1;
		}
		return days;
	}	
public:
	int findWeek (date findDate, date baseDate, int baseWeek) {
		bool isLarger = isDateLarger(findDate, baseDate);
		int days, weekDay;
		if (isLarger) {
			days = diffDays(baseDate, findDate);
			weekDay = (baseWeek + days) % 7;
		} else {
			days = diffDays(findDate, baseDate);
			weekDay = (baseWeek - (days % 7) + 7) % 7;
		}
		//cout << days << endl;
		return weekDay;
	}
};

int main() {
	solution sol;
	date baseDate;
	baseDate.yy = 2015;
	baseDate.mm = 3;
	baseDate.dd = 16;
	date findDate;
	findDate.yy = 2007;
	findDate.mm = 4;
	findDate.dd = 1;
	int weekday = sol.findWeek(findDate, baseDate, 1);
	cout << weekDays[weekday] << endl;
	return 0;
}

- My Code March 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

there are three cases to figure:
1. if month is 2(feb) then check for leap year.
2. if month is 12(dec) then check if it crosses 31st dec then new month will contain new year.
3. check same for 1(jan).
else in other cases use general method to count number of days in month and etc.

- skg December 13, 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