Online Assessment Questions !
Anonymous User
561

Q1. You have a hamster, and you record the time when it falls asleep and wakes up (in 24-hour clock format). The hamster will never sleep for more than 18 hours at once and will never stay awake for more than 18 hours at once.
Your task is to calculate the total sleeping time, and the total waking time between the first record and the last record.

Example:
Suppose an input is as follows.
1
3
05:00 06:00
20:00 08:30
01:00 01:30
The total waking time is: 14 hours + 16 hours 30 minutes = 30 hours 30 minutes (1830 minutes).
The total sleeping time is: 1 hour + 12 hours 30 minutes + 30 minutes = 14 hours (840 minutes).

Q2. You have N programs and want to run each of them exactly once. Each program takes exactly one hour to complete. You can run multiple programs in parallel, but some programs depend on the output from one or more other programs and thus can be run only after their completion. Given the dependency between programs, please compute the minimum number of hours you need to run all programs.(Found this hard maybe it's easy ! )

Example:
Suppose the input is as follows

1
5 5
1 3
3 4
2 3
3 5
1 4

Here taking the dependencies into consideration we can do the the task in 3 hours in this manner each hour as we can perform parralel tasks too.
[[1,2], [3] , [4,5]].

Figured out the solution to first Question in like 10 minutes but the Question 2 went hard on me and I struggled for like 30 minutes until I figured out the solution but it was'nt optimal. If annyone can figure out a optimal solution do tell in the comments.
Peace !

Comments (2)