Skip to the code
cf.
+25 XP

#148 Slices With Every Event Type

medium

A checkout funnel logs events as letters in events: a for add-to-cart, b for begin-checkout, and c for complete-purchase. An analyst wants to know how many slices of the log contain at least one of each event type.

Write countFullSlices(events) that returns the number of non-empty runs of neighboring events that contain at least one a, one b, and one c.

Example 1

Input: events = "abcabc"
Output: 10

Every slice of length 3 or more contains all three letters: 4 + 3 + 2 + 1 = 10.

Example 2

Input: events = "aaacb"
Output: 3

aaacb, aacb, and acb.

Constraints

  • 0 <= events.length <= 50000
  • events contains only a, b, and c.
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).