Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: Job sequencing: five jobs (deadline, profit) are (2, 100), (1, 19), (2, 27), (1, 25), (3, 15). Each job takes one unit of time and at most one job runs per unit time; a job earns its profit only if it finishes by its deadline. What is the maximum total profit?
- A. 152
- B. 140
- C. 142
- D. 127
Correct answer: C. 142
Sort by profit and place each job in the latest free slot before its deadline: 100 in slot 2, 27 in slot 1, 25 and 19 find no slot, 15 in slot 3 → 142. Ignoring deadlines (top three profits) gives 152, scheduling by earliest deadline first picks 25 over 27 (140), and using only two slots gives 127.
More Coding Interview Problems questions
- Problem: Boats carry at most 2 people and a weight limit of 10 per boat. Four people weigh 3, 5, 3 and 4. What is the minimum number of…
- Problem: What is the smallest integer x with x·x ≥ 1,000,000,000?
- Problem: A grid holds oranges: 2 = rotten, 1 = fresh, 0 = empty: [[2,1,1],[1,1,0],[0,1,1]]. Each minute every fresh orange adjacent…
- Problem: Courses 0–5 have prerequisites: 1 needs 0, 2 needs 1, 3 needs 2, 4 needs 5, 5 needs 4. A course can be taken only after all its…
- Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7]…
- Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it…