Data Structures & AlgorithmsHardProduct Company SDE · scheduling OA
Problem: Tasks with (duration, deadline) are (3,5), (2,4), (4,9), (1,3). Scheduling by earliest deadline first, how many tasks finish on or before their deadlines? Run the code.
Problem: Tasks with (duration, deadline) are (3,5), (2,4), (4,9), (1,3). Scheduling by earliest deadline first, how many tasks finish on or before their deadlines? Run the code.
tasks = [(3, 5), (2, 4), (4, 9), (1, 3)]
tasks.sort(key=lambda t: t[1])
t = 0
ok = 0
for d, dl in tasks:
t += d
if t <= dl:
ok += 1
print(ok)What is printed?- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: B. 2
In deadline order the finish times are 1, 3, 6, 10 against deadlines 3, 4, 5, 9, so tasks with durations 1 and 2 meet their deadlines and the count is 2.
More Coding Interview Problems questions
- Problem: Which statement about the greedy algorithm for 'minimum number of lecture rooms' (interval partitioning) is correct?
- Problem: Which statement about bitmask DP for a Hamiltonian path problem on n = 20 vertices is correct in the standard sense?
- Problem: Which claim about a binary search over a rotated sorted array (no duplicates) finding the minimum element is correct?
- Problem: How many pairs (i < j) of a = [1, 2, 4, 5, 7, 8] have a[i] - a[j] divisible by 3? Run the code. python a = [1, 2, 4, 5, 7, 8]…
- Problem: What is the minimum number of meeting rooms needed for intervals [0,30], [5,10], [15,20]? Run the sweep-line code. python iv =…
- Problem: How many inversions (pairs i < j with a[i] > a[j]) does a = [2, 0, 2, 1, 1, 0] have? Run the code. python a = [2, 0, 2, 1, 1, 0]…