Problem

Integrity Score

Learn this problem
SalesforceFULLTIMEOA
See Salesforce hiring insights

Problem statement

A data packet is represented as a string dataPacket of lowercase English letters. Each character has the following value:

  • a and b have value 1.
  • c, d, and e have value 2.
  • f, g, and h have value 3.
  • i, j, and k have value 4.
  • l, m, and n have value 5.
  • o, p, and q have value 6.
  • r, s, and t have value 7.
  • u, v, and w have value 8.
  • x, y, and z have value 9.

The integrity score is the number of substrings whose character-value sum is divisible by the substring length. Return the integrity score of dataPacket as a long.

Function

integrityScore(dataPacket: String) → long

Examples

Example 1

dataPacket = "cat"return = 4

The character values are [2, 1, 7]. The valid substrings are "c", "a", "t", and "at". The substring "at" has sum 8 and length 2, so its sum is divisible by its length.

Constraints

  • 1 <= dataPacket.length <= 10^5
  • dataPacket consists of lowercase English letters.

More Salesforce problems

drafts saved locally
public long integrityScore(String dataPacket) {
  // write your code here
}
dataPacket"cat"
expected4
checking account