Back to Datadog questions
CodingSoftware Engineer

Integrity Score

Frequency: Reported


A network security analyst must verify the integrity of data transmitted over a secure network. Each data packet consists of a string of characters, and each character has been assigned a numerical value according to a predetermined mapping.

The integrity score of a data packet is the number of nonempty substrings for which the sum of the numerical values of the characters is divisible by the substring's length. Return that count.

Mapping preserved in the source

The screenshot visibly preserves the following portion of the mapping:

Letterabcdefghijklmnop
Value1122233344455566

The right side of the table is cropped from the source screenshot. The worked example separately establishes that y maps to 9. Do not infer the omitted entries from this file alone.

Example

For dataPacket = "hey", the nonempty substrings are:

  1. "h": sum 3, divisible by length 1.
  2. "e": sum 2, divisible by length 1.
  3. "y": sum 9, divisible by length 1.
  4. "he": sum 3 + 2 = 5, not divisible by length 2.
  5. "hey": sum 3 + 2 + 9 = 14, not divisible by length 3.
  6. "ey": sum 2 + 9 = 11, not divisible by length 2.

Therefore, return 3.

Function

text
integrityScore(string dataPacket) -> int
  • dataPacket is a string of length n.
  • Return the number of nonempty substrings that meet the criterion.

No numeric constraints were visible in the recovered screenshot.