Skip to the code
cf.
+25 XP

#132 Calm Spell for the Support Desk

medium

A support desk gets chats[i] chats in minute i. In some minutes the agent on duty is overloaded (overloaded[i] is 1), and every chat in those minutes ends unhappy. In other minutes (0) every chat ends happy.

A manager can step in for exactly m minutes in a row once per day, and during those minutes every chat ends happy. Write mostHappyChats(chats, overloaded, m) that returns the largest possible number of happy chats for the day.

Example 1

Input: chats = [1,0,1,2,1,1,7,5], overloaded = [0,1,0,1,0,1,0,1], m = 3
Output: 16

Without help 10 chats are happy. Stepping in for the last 3 minutes saves 1 + 5 = 6 more.

Example 2

Input: chats = [4], overloaded = [0], m = 1
Output: 4

The only minute is already happy.

Constraints

  • 1 <= m <= chats.length <= 100000
  • overloaded.length === chats.length
  • 0 <= chats[i] <= 1000
  • overloaded[i] is 0 or 1.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).