Mid/Senior

Count the Number of Experiments

You are given a list experiments, where each experiments[i] = [platform, experiment_name] represents one experiment performed on a platform.

There are exactly three possible platforms:

  • Android
  • IOS
  • Web

There are exactly three possible experiment names:

  • Reading
  • Sports
  • Programming

Return a 3 x 3 integer matrix counts, where:

  • Rows are ordered by platform as Android, IOS, Web.
  • Columns are ordered by experiment name as Reading, Sports, Programming.
  • counts[i][j] is the number of experiments performed for the corresponding platform and experiment name.

Every platform/experiment-name combination must be represented, even if its count is 0. Your solution should run in O(n) time, where n is the number of experiments.

Example 1
Inputexperiments = [["Android","Reading"],["Android","Reading"],["IOS","Sports"],["Web","Programming"],["Web","Programming"],["Web","Reading"]]
Output[[2,0,0],[0,1,0],[1,0,2]]
Android has two Reading experiments, IOS has one Sports experiment, and Web has one Reading plus two Programming experiments.
Example 2
Inputexperiments = []
Output[[0,0,0],[0,0,0],[0,0,0]]
With no experiments, every platform and experiment-name combination has count 0.

Constraints

  • 0 <= experiments.length <= 10^5
  • experiments[i].length == 2
  • experiments[i][0] is one of "Android", "IOS", or "Web"
  • experiments[i][1] is one of "Reading", "Sports", or "Programming"

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate