Count Eligible Package Codes
Problem statement
In a logistics company, the integer array packageCodes contains the codes assigned to processed packages.
Return the number of array entries that satisfy both conditions:
- The code is divisible by
3. - Its ordinary decimal representation contains the digit
7at least twice.
Count every qualifying occurrence separately, even when the same code appears more than once.
Practice domain
Codes are non-negative integers. A direct scan of each code and its digits is sufficient.
Function
countEligiblePackageCodes(packageCodes: int[]) → intExamples
Example 1
packageCodes = [771,3702,3727,777,273,777,456]return = 3771contains two7s and is divisible by3.3702contains only one7.3727contains two7s but is not divisible by3.- Each occurrence of
777contains three7s and is divisible by3; count both occurrences. 273contains only one7, and456contains none.
The qualifying entries are 771, 777, and 777, so return 3.
Example 2
packageCodes = [0,77,707,717,7777,7770]return = 2Only 717 and 7770 satisfy both conditions. Two or more 7s alone are insufficient, and zero contains no 7.
Constraints
1 <= packageCodes.length <= 1000.0 <= packageCodes[i] <= 10^9.