Tap here to switch tabs
Problem
Submissions

Problem: Count Items Matching a Rule

med
30 min
Try to solve the Count Items Matching a Rule problem.

Statement

You are given an array items, where each items[i] = [type_i, color_i, name_i] describes the type, color, and name of the ithi^{ th} item. You are also given two strings, ruleKey and ruleValue.

The ithi^ {th} item is considered a match to the rule if one of the following conditions is satisfied:
• ruleKey == "type" and ruleValue == type_i
• ruleKey == "color" and ruleValue == color_i
• ruleKey == "name" and ruleValue == name_i

Return the total count of items that match the specified rule.

Constraints:

  • 1≤1 \le items.length ≤104\le 10^4

  • 1≤1 \le type_i.length, color_i.length, name_i.length, ruleValue.length ≤10\le 10

  • ruleKey is equal to either "type", "color", or "name".

  • All strings consist only of lowercase letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Items Matching a Rule

med
30 min
Try to solve the Count Items Matching a Rule problem.

Statement

You are given an array items, where each items[i] = [type_i, color_i, name_i] describes the type, color, and name of the ithi^{ th} item. You are also given two strings, ruleKey and ruleValue.

The ithi^ {th} item is considered a match to the rule if one of the following conditions is satisfied:
• ruleKey == "type" and ruleValue == type_i
• ruleKey == "color" and ruleValue == color_i
• ruleKey == "name" and ruleValue == name_i

Return the total count of items that match the specified rule.

Constraints:

  • 1≤1 \le items.length ≤104\le 10^4

  • 1≤1 \le type_i.length, color_i.length, name_i.length, ruleValue.length ≤10\le 10

  • ruleKey is equal to either "type", "color", or "name".

  • All strings consist only of lowercase letters.