Microsoft OA

microsoft logo
microsoft
June 15, 20255 reads

Summary

This post details a specific algorithmic problem encountered during a Microsoft Online Assessment.

Full Experience

Microsoft OA:

1.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.

Example

Consider n = 1, m = 5, schedule[][] = ["10001"] and k = 1.

The 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.

Function Description

Complete the function getMinimum Time in the editor with the following parameters: int schedule[n][m]: binary strings each of length m, which denote the schedule of the school

int k. the number of lectures the student can skip

Returns int. the minimum total time the student is required to attend the school.

Constraints:

  1. 1<=k, m, n <=200
  2. scheduled[i][j] == '0' or '1'
  3. It is gauranteed that the length of each schedule[i] (0<=i<n) is equal to m.

Interview Questions (1)

Q1
Minimum Time to Attend School with Skippable Lectures
Data Structures & AlgorithmsHard

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.

Example

Consider n = 1, m = 5, schedule[][] = ["10001"] and k = 1.

The 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.

Function Description

Complete the function getMinimum Time in the editor with the following parameters: int schedule[n][m]: binary strings each of length m, which denote the schedule of the school

int k. the number of lectures the student can skip

Returns int. the minimum total time the student is required to attend the school.

Constraints:

  1. 1<=k, m, n <=200
  2. scheduled[i][j] == '0' or '1'
  3. It is gauranteed that the length of each schedule[i] (0<=i<n) is equal to m.
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!