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:
AndroidIOSWeb
There are exactly three possible experiment names:
ReadingSportsProgramming
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
Input
experiments = [["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
Input
experiments = []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"