You are given an array of commands. There are only three possible commands: cmd1, cmd2, and cmd3. Your task is to return an array of size 3 that contains the frequency of each command in the input array, in the order [frequency of cmd1, frequency of cmd2, frequency of cmd3].
Also, any element in the form of ![index] refers to the same command that was present at the position in the input array. Note that indexing starts from 1 (not 0).
Complete the function commandFrequencyCounter in the editor.
commandFrequencyCounter has the following parameter:
String[] commands: an array of commands
Returns
int[]: an array of size 3 containing the frequency of each command
Examples
01 · Example 1
commands = ["cmd1", "cmd2", "cmd3", "!1", "!2", "cmd3", "cmd1"] return = [3, 2, 2]
At index 4 (
!1), the command is the same as the command at index 1 (cmd1).
At index 5 (!2), the command is the same as the command at index 2 (cmd2).More Uber problems
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
public int[] commandFrequencyCounter(String[] commands) {
// write your code here
}
commands["cmd1", "cmd2", "cmd3", "!1", "!2", "cmd3", "cmd1"]
expected[3, 2, 2]
checking account