Practice Count Items Matching a Rule
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Each item is [type,color,name]. Count items whose field named by ruleKey equals ruleValue exactly. ruleKey selects type, color, or name; the other two fields do not affect whether an item matches.
Source: Count Items Matching a Rule on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"
Output
1
# Example 2
Input
items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"
Output
2
Constraints
1 <= items.length <= 10^4
1 <= typei.length, colori.length, namei.length, ruleValue.length <= 10
ruleKey is equal to either "type", "color", or "name".
All strings consist only of lowercase letters.
Related LeetCode Problems
Practice more problems similar to Count Items Matching a Rule.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.