Skip to the code
cf.
+25 XP

#535 Common Steps Across Three Funnels

medium

An analytics tool recorded the event names of three user sessions, first, second, and third, in time order. A product manager wants the longest list of events that happens in all three sessions in the same order, with other events allowed in between.

Write commonSteps(first, second, third) that returns the length of the longest common subsequence of the three arrays.

Example 1

Input: first = ["view","cart","pay"], second = ["view","pay"], third = ["view","search","pay"]
Output: 2

view then pay happens in all three sessions.

Example 2

Input: first = ["open"], second = ["close"], third = ["open"]
Output: 0

No event appears in all three.

Constraints

  • 0 <= first.length, second.length, third.length <= 100
  • Event names are non-empty strings.
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).