Integrity Score
Updated
Problem statement
A data packet is represented as a string dataPacket of lowercase English letters. Each character has the following value:
aandbhave value1.c,d, andehave value2.f,g, andhhave value3.i,j, andkhave value4.l,m, andnhave value5.o,p, andqhave value6.r,s, andthave value7.u,v, andwhave value8.x,y, andzhave value9.
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) → longExamples
Example 1
dataPacket = "cat"return = 4The 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^5dataPacketconsists of lowercase English letters.
More Salesforce Online Assessment questions
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
- Run-Length String CompressionOA · Seen Sep 2026
- Maximum Requests in WindowOA · Seen Sep 2026
- Final Pod Counts After LogsOA · Seen Aug 2026
- Minimum Removals to Balance ArrayOA · Seen Aug 2026
- Is This Date a Weekend?OA · Seen Aug 2026
- Maximum Barbell WeightOA · Seen Jul 2026