Count Items Matching A Rule Leetcode