Skip to the code
cf.
+25 XP

#625 Multiply Two Encoded Signals

medium

A metrics dashboard stores long time series in run-length form: [[value, count], ...] means value repeated count times, run after run. To show a weighted series, it multiplies two series point by point.

Write multiplyEncoded(a, b) where a and b describe series of the same total length. Return the run-length form of the point-by-point product. Neighboring runs in the answer must have different values (merge them if needed), and every count is positive.

The expanded series can be huge, so don't expand them.

Example 1

Input: a = [[1,3],[2,3]], b = [[6,3],[3,3]]
Output: [[6,6]]

1 * 6 three times, then 2 * 3 three times: all six products are 6, so they merge.

Example 2

Input: a = [[2,2],[5,1]], b = [[1,1],[3,2]]
Output: [[2,1],[6,1],[15,1]]

Products are 2, 6, 15.

Constraints

  • 0 <= a.length, b.length <= 10^4
  • 1 <= count <= 10^9
  • -10^4 <= value <= 10^4
  • Both series have the same total count.
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).