Get Minimum Time
Updated
Problem statement
A student at HackerSchool is provided with a schedule of n days, where each day can have up to m hours of lecture classes.
The schedule is represented by a binary matrix schedule[][], where schedule[i][j] = '1' means there is a lecture at the jth hour of the ith day, and schedule[i][j] = '0' means there is no lecture at that time.
If the student attends the first lecture at the xth hour and the last lecture at the yth hour on a single day, then they spend (y - x + 1) hours at school that day. The student is allowed to skip up to k lectures in total over all n days.
Determine the minimum total time (in hours) the student needs to attend school over all n days, given that they can skip lectures optimally.
Function
getMinimumTime(schedule: char[][], k: int) → int
Complete the function getMinimumTime in the editor with the following parameters:
char schedule[n][m]: binary strings each of lengthm, which denote the schedule of the schoolint k: the number of lectures the student can skip
Returns
int: the minimum total time the student is required to attend the school.
Examples
Example 1
schedule = [['1', '0', '0', '0', '1']]k = 1return = 1The student can skip the last lecture of the first day, that is, schedule[0][4]. Then, they only have to attend one lecture at the 0th hour, so the total time spent at school = 1, which is the minimum possible. Thus, the answer is 1.
Constraints
1 <= k, m, n <= 200schedule[i][j]== '0' or '1'- It is guaranteed that the length of each
schedule[i](0 <= i < n) is equal tom.
More Microsoft interview questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Authentication SystemOA · Seen Nov 2026
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Grid Paths with Override PassesIMC Trading · OAIMC Trading interview questions
- Largest Square of OnesOpenAI · OAOpenAI interview questions
- Minimum Moves to Spread Stones Across a GridAmerican Express · OAAmerican Express interview questions
- Maximum Reward (Intuit India)Intuit · OAIntuit interview questions
- Largest Plus SignxAI · OAxAI interview questions
- Calculate the Max ValueAmazon · OA
- Largest Square of 1'sFactSet · OAFactSet interview questions
- Longest Border-Ending Diagonal PatternZipRecruiter · OAZipRecruiter interview questions
- Count Grid Words with One TurnCapital One · OACapital One interview questions
- Minimum Falling Path SumScale AI · OAScale AI interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)