325. Minimum Time at the Office After Skipping Meetings
Minimum Time at the Office After Skipping Meetings
An employee has a meeting schedule for n days. Each day is divided into m hourly slots numbered from 0 to m - 1.
The schedule is represented by a list of binary strings. In schedule.get(i):
  • '1' at index j means there is a meeting during hour j of day i.
  • '0' at index j means there is no meeting during that hour.
If the first meeting attended on a day is at hour x and the last is at hour y, the employee must stay at the office for y - x + 1 hours. Any free slots between these meetings are also included.
The employee may skip at most k meetings across all days. If every meeting on a day is skipped, the time spent at the office that day is 0.
Find the minimum total time the employee must spend at the office by choosing the meetings to skip optimally.

Method Signature

int getMinimumTime(List<String> schedule, int k)

Parameters

  • schedule: A list of binary strings representing the meeting schedule for all days.
  • k: The maximum number of meetings that may be skipped.

Returns

Return the minimum total number of hours the employee must spend at the office across all days.

Constraints

  • n = schedule.size()
  • m = schedule.get(0).length()
  • 1 ≤ n, m, k ≤ 200
  • schedule.get(i).length() = m for 0 ≤ i < n.
  • Every character in schedule.get(i) is either '0' or '1'.

Examples

Example 1

Method call: getMinimumTime(schedule = List.of("10101", "01010"), k = 2)
On the first day, the employee can skip the meetings at hours 0 and 4. Only the meeting at hour 2 remains, requiring 1 hour.
The second day has meetings at hours 1 and 3, requiring 3 hours. Therefore, the minimum total time is 1 + 3 = 4 hours.
Output: 4

Example 2

Method call: getMinimumTime(schedule = List.of("1000001", "0011100", "0100010"), k = 3)
One optimal choice is to skip one meeting on each day. The required times for the three days then become 1, 2, and 1 hours respectively.
Therefore, the minimum total time is 1 + 2 + 1 = 4 hours.
Output: 4


Please use Laptop/Desktop or any other large screen to add/edit code.