Count Training Programs in a Maximum-Value Schedule
Updated
Problem statement
A college offers training programs in one day. Each element of programs is a string label,start,end,value, such as P1,14,15,200. Times are integer hours; 14 means 14:00. A student can attend any subset with no overlapping intervals. A program ending at an hour may be followed by one starting at that same hour.
Maximize the sum of program values. Among schedules with that maximum value, choose one with the greatest number of programs. Return that number of programs, rather than the total value. Return 0 when no programs exist.
For this exercise, assume the exact comma encoding, integer-hour bounds, nonnegative values, endpoint compatibility and count tie rule stated here.
Function
countTrainingPrograms(programs: String[]) → intExamples
Example 1
programs = ["P1,14,15,200","P2,18,19,200","P3,16,19,100","P4,15,18,100"]return = 3Attend P1, P4 and P2 for total value 500. The returned answer is the number of programs, 3.
Example 2
programs = ["A,0,2,10","B,0,1,5","C,1,2,5"]return = 2Both A alone and B followed by C have value 10. The tie rule chooses the two-program schedule.
Constraints
- 0 <= programs.length <= 200.
- Each programs[i] has 7 to 32 ASCII characters and exactly four comma-separated fields: label,start,end,value, with no spaces. Labels are unique and contain 1 to 10 ASCII letters or digits. Numeric fields use decimal digits with no leading zero except the number 0.
- 0 <= start < end <= 24 and 0 <= value <= 10000. Times are integer hours in one day.
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
- Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Highway Billboard RevenueExpedia · ONSITE INTERVIEWExpedia interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximum Profit in Job SchedulingAmazon · PHONE SCREEN
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Maximum Event Value with an Attendance LimitSnowflake · PHONE SCREENSnowflake interview questions
- Find Minimum TimeAlphaSense · OA
- Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
Interview reports that mention this question
JP Morgan Chase interview experiences
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)