Skip to content

Instantly share code, notes, and snippets.

@aldrinjenson
Created October 20, 2022 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aldrinjenson/72cb663e2050c4191cff4eae40c27f73 to your computer and use it in GitHub Desktop.
Save aldrinjenson/72cb663e2050c4191cff4eae40c27f73 to your computer and use it in GitHub Desktop.
const BREAK_DURATION = 1
const INTERVIEW_DURATION = 2
const START_TIME = 9
const BREAK_START_HOUR = 14
const MEETING_END_TIME = 18
class Room {
currTime = START_TIME;
constructor(roomName = '') {
this.roomName = roomName
}
getName = () => {
return this.roomName
}
getCurrTime = () => {
return this.currTime
}
doMeetingAndBreak = () => {
if (this.currTime === BREAK_START_HOUR - 1 || this.currTime === BREAK_START_HOUR) {
this.currTime += BREAK_DURATION
}
this.currTime += INTERVIEW_DURATION
}
}
class Schedule {
constructor({ attendees, interviewers, rooms }) {
this.attendees = attendees
this.interviewers = interviewers
this.rooms = rooms
}
calculateSchedule = () => {
const limitingValue = Math.min(this.interviewers.length, this.rooms.length)
console.log({ attendees: this.attendees, interviewers: this.interviewers, rooms: this.rooms.map(r => r.getName()) });
console.log('Attendee\tInterviewer\tRoom\tTime');
const schedule = []
let i, j
let timeOver = false
for (i = 0; !timeOver && i < this.attendees.length; i++) {
for (j = i; !timeOver && j < limitingValue + i && j < this.attendees.length; j++) {
const attendee = this.attendees[j]
const matchedRoom = this.rooms[j % limitingValue]
const startTime = Math.floor((matchedRoom.getCurrTime()) % 12)
matchedRoom.doMeetingAndBreak()
const endTime = Math.floor((matchedRoom.getCurrTime()) % 12)
if (matchedRoom.getCurrTime() > MEETING_END_TIME) {
console.log(attendee + ' will be having meeting tomorrow');
timeOver = true
break;
}
const obj = {
attendee,
interviwer: this.interviewers[j % limitingValue],
room: matchedRoom.getName(),
time: `${startTime} - ${endTime}`
}
schedule.push(obj)
}
i = j - 1
}
console.log(schedule);
// return schedule
}
}
new Schedule({ attendees: ['1', '2', '3', '4', '5'], interviewers: ['A', 'B', 'C'], rooms: [new Room('R1'), new Room('R2')] }).calculateSchedule()
new Schedule({ attendees: ['1', '2', '3', '4', '5'], interviewers: ['A', 'B', 'C'], rooms: [new Room('R1'), new Room('R2'), new Room('R3')] }).calculateSchedule()
new Schedule({ attendees: ['1', '2', '3', '4', '5', '6', '7'], interviewers: ['A', 'B'], rooms: [new Room('R1'), new Room('R2')] }).calculateSchedule()
new Schedule({ attendees: ['1', '2', '3', '4', '5'], interviewers: ['A', 'B'], rooms: [new Room('R1'), new Room('R2'), new Room('R3')] }).calculateSchedule()
new Schedule({ attendees: ['1', '2', '3', '4', '5'], interviewers: ['A'], rooms: [new Room('R1'), new Room('R2')] }).calculateSchedule()
@aldrinjenson
Copy link
Author

aldrinjenson commented Oct 20, 2022

Question:
https://github.com/YogeshSharma0201/ThoughtWorks-pair-coding-round/blob/master/README.md

Question:

Our recruiter wants to do a scheduling of the Interview process. There are n attendees, m interviewers and r rooms.
An interview lasts 2 hours. A day starts at 9.00am, ends at 6:00pm with a break of one hour, at 2:00pm to 3:00pm.
The aim of the program is to schedule interviews in a room without overlapping timings. An Interview is scheduled
If there is an interviewer, an attendant and an available room. If we are not able to fit all the interviews
before the day ends, accommodate as many as you can in the day and print a message mentioning attendees who
could not be interviewed.

Sample Input:

Attendees:

1 2 3 4 5

Interviewers:

A B C

Rooms:

R1 R2

Considering the input above, minimum requirement for the program is to model the problem using OOPS and give
the output with no overlapping of the timings of the rooms and interviewers.

OUTPUT:

OUTPUT

Solution:

I have included the code in the repository which helped me clear this round. The objective of this round is to test your OOPS concept.
Therefore focus on designing your code properly.

To test the code provide following input:

5

1 2 3 4 5

3

A B C

2

R1 R2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment