FastPrepLong Break
Problems/Long Break

Long Break

WeRide logoWeRide● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are organizing an event with several presentations in one room. The event runs from time 0 to time t. Presentation i runs from start[i] to finish[i]. The presentations do not overlap, but one may start right when the previous one ends. Any time with no presentation is free time for networking.

You may move up to k presentations to a different start time. A moved presentation keeps its length and must stay inside the event. The order of the presentations cannot change, and they still may not overlap. Your goal is to make the longest stretch of free time as long as you can. Return that length.

Complete the function maxNetworkingTime in the editor.

maxNetworkingTime has the following parameters:

  • int t: the time the event ends
  • int[] start: the start time of each presentation
  • int[] finish: the end time of each presentation
  • int k: the most presentations you may move

The function returns an int: the longest stretch of free time you can make.

Function

maxNetworkingTime(t: int, start: int[], finish: int[], k: int) → int

Examples

Example 1

t = 15start = [4, 6, 7, 10]finish = [5, 7, 8, 11]k = 2return = 6
Example 1 illustration

The event runs from time 0 to t = 15. There are n = 4 presentations, at 4 to 5, 6 to 7, 7 to 8 and 10 to 11. You may move up to k = 2 of them.

Without moving anything, the free stretches are 0 to 4, 5 to 6, 8 to 10 and 11 to 15. The longest has length 4.

Move the last presentation (10 to 11) earlier, to 8 to 9. Now the free time after it runs from 9 to 15, which is 6 long. Moving the first presentation later gives only 5. The longest free stretch you can make is 6.

Constraints

  • 1 ≤ t ≤ 109
  • 1 ≤ n ≤ 105, where n is the length of start and finish
  • 0 ≤ k ≤ n
  • 0 ≤ start[i] < finish[i] ≤ t
  • The presentations are listed in time order and do not overlap: finish[i] ≤ start[i + 1]

More WeRide interview questions

  • Drawing EdgeOA · Seen Aug 2026
  • Paint the CeilingOA · Seen Aug 2026
  • Unequal Block StructureOA · Seen Aug 2026
  • Checking Your Route 🚗OA · Seen Mar 2024
  • Meetup Schedule 📆OA · Seen Feb 2024

Similar questions at other companies

  • Count Equal-Distinct Character PartitionsInfosys · OAInfosys interview questions
  • Maximum Order VolumeSnowflake · OASnowflake interview questions
  • Max Subarray Filled With ZerosGoogle · OAGoogle interview questions
  • Smart Gardener (Intuit India)Intuit · OAIntuit interview questions
  • Cinema ShowsAmazon · OA
  • Fewest Fountains to Water the GardenDocuSign · OADocuSign interview questions
  • Minimum Length After Removing Arithmetic TriplesMedia.net · PHONE SCREEN
  • New 21 Game ProbabilityUiPath · PHONE SCREEN
  • Deployment Window SchedulerStripe · OAStripe interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
All WeRide interview questionsSee WeRide hiring insights
Saved
class Solution {
    public int maxNetworkingTime(int t, int[] start, int[] finish, int k) {
        // write your code here
    }

}
Checking account…