Count Items Matching a Rule

Easy

Description

Given an array items where each item is [type, color, name], count items matching the given ruleKey and ruleValue.

Examples

Input:items = [["phone","blue","pixel"],["computer","silver","lenovo"]], ruleKey = "color", ruleValue = "silver"
Output:1
Explanation:

Only lenovo matches.

Input:items = [[1]], ruleKey = "color", ruleValue = "silver"
Output:1
Explanation:

With a single item, checking its attribute against the rule yields 1 match.

Input:items = [["laptop","black","dell"],["mouse","white","logitech"],["keyboard","black","corsair"],["monitor","black","samsung"]], ruleKey = "color", ruleValue = "black"
Output:3
Explanation:

Three items match the rule: laptop (black dell), keyboard (black corsair), and monitor (black samsung). The mouse is white so it doesn't match.

Constraints

  • 1 ≤ items.length ≤ 10^4

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!