A learning app suggests a study plan. Lesson i takes lessons[i][0] days and must be finished by the end of day lessons[i][1]. You study one lesson at a time, starting at day 0, and each lesson's days run back to back. A lesson that starts at day t finishes at day t + duration, and it counts only if that is at most its deadline.
Write mostLessons(lessons) that returns the largest number of lessons you can finish on time, choosing which lessons to take and in what order.
Input: lessons = [[50,100],[300,900],[500,800],[1200,2000]] Output: 3
The lessons due at 100, 800, and 900 finish at days 50, 550, and 850. Taking all four would end at day 2050, past the last deadline 2000.
Input: lessons = [[3,2],[4,3]] Output: 0
Each lesson takes longer than its deadline allows.
1 <= lessons.length <= 10^41 <= duration, deadline <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #402 Fit the Most Lessons Before Deadlines. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.