MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / countMatches

Method countMatches

CountItemsMatchingARule.java:2–24  ·  view source on GitHub ↗
(List<List<String>> items, String ruleKey, String ruleValue)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
3
4 int ans=0;
5 for(List l : items)
6 {
7 if((ruleKey.equals("type"))&&((l.get(0)).equals(ruleValue)))
8 {
9 ans++;
10 }
11 else if((ruleKey.equals("color"))&&((l.get(1)).equals(ruleValue)))
12 {
13 ans++;
14 }
15 else if((ruleKey.equals("name"))&&((l.get(2)).equals(ruleValue)))
16 {
17 ans++;
18 }
19
20 }
21
22 return ans;
23
24 }
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected