Green Bricks Interview Question
Software Engineer / DevelopersTeam: test alpha
Country: United States
Interview Type: Written Test
Covert Days of the week to the following
Sunday - 0
Monday - 1
Tuesday -2
Wednesday -3
Thursday - 4
Friday - 5
Saturday - 6
Now initialize Course[x][0], Course[x][1] and Course[x][2] as course X taken on the 3 days mentioned in the input.
int bestIndex=-1;
for(int i=1;i<1<<7;i++)
{
for(int j=0;j<Subjects.Length;j++)
{
if(i & 1<<Course[j][0] && i & 1<<Course[j][1] && i & 1<<Course[j][2] )
{
CourseIndex[i]=CourseIndex[i]+1
}
if(CourseIndex[i]>=m)
{
bestIndex=i;
}
}
}
The fact that the space of possible outputs is so small immediately makes this problem trivial. Unless the required number of courses is 0, the number of possible sets of days that could be the answer is (7 pick 3) + (7 pick 4) + (7 pick 5) + (7 pick 6) + (7 pick 7) = 78. For each of the 78 possibilities, check them in order of size and see if they work. Output the first one that works.
The second sample input and output seems to be off. Shouldn't sample output for the input stream me WED THU and not TUE WED THU ?
- van May 30, 2012