FastPrepCount Eligible Package Codes

Count Eligible Package Codes

TikTok logoTikTok● EasyNEW GRADOA
Learn

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 7 at 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[]) → int

Examples

Example 1

packageCodes = [771,3702,3727,777,273,777,456]return = 3
  • 771 contains two 7s and is divisible by 3.
  • 3702 contains only one 7.
  • 3727 contains two 7s but is not divisible by 3.
  • Each occurrence of 777 contains three 7s and is divisible by 3; count both occurrences.
  • 273 contains only one 7, and 456 contains none.

The qualifying entries are 771, 777, and 777, so return 3.

Example 2

packageCodes = [0,77,707,717,7777,7770]return = 2

Only 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.

More TikTok problems

See TikTok hiring insights
public int countEligiblePackageCodes(int[] packageCodes) {
    // write your code here
}
packageCodes[771,3702,3727,777,273,777,456]
expected3
Checking account…