Imagine you're working as a digital inventory manager for an online store! ๐๏ธ
You have a collection of items in your inventory, where each item is described by three properties: [type, color, name]. Your task is to count how many items match a specific filtering rule.
A filtering rule consists of two parts:
- ruleKey: Which property to filter by (
"type","color", or"name") - ruleValue: The exact value that property should have
An item matches the rule if the specified property equals the target value. For example, if ruleKey = "color" and ruleValue = "red", then only red items will match.
Goal: Return the total count of items that satisfy the given filtering rule.
Example: If you have items like [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]] and rule ruleKey="type", ruleValue="phone", the answer is 2 because two items are phones.
Input & Output
Constraints
- 1 โค items.length โค 104
- 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