Answer: TERRA Hiring | Off-Campus OA (2025) | Count Items Matching a Rule
Answer · Posted Jun 2026
Approach Determine the column index based on ruleKey: "type" → 0 "color" → 1 "name" → 2 Traverse every item. Compare the value at the selected index with ruleValue. Count all matching items. Strategy Convert the rule into a column index. Perform a single traversal through the list. Increment the counter whenever a match is found. Java Code import java.util.*; class Solution { public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) { int index; if (ruleKey.equals("type")) index = 0; else ...
The full answer & interview discussion are available to premium members.
Log in Create a free account