Problem · Array
Score Points
Learn this problemProblem statement
There is a board with N cells (numbered from 0 to N-1) arranged in a row. The board is described by an array points and a string tokens, both of length N. The K-th cell of the string tokens is either 'T' or 'E', indicating whether the K-th cell contains a token or is empty.
If the K-th cell contains a token, we assign the number of points equal to points[K]. Additionally, we score another for every pair of adjacent tokens. The goal is the total number of points we score?
𓂃 ོ𓂃Big shoutout to Aura Man for all the support! 🐳𓂃 𓈒𓏸
Function
scorePoints(points: int[], tokens: String) → intExamples
Example 1
points = [3, 4, 5, 2, 3]tokens = "TEETT"return = 9Cells 0, 3 and 4 contain tokens.
The sum of points in these cells is 8.
Also, there is one pair of adjacent cells with tokens, which result in 1 extra point. The function should return 9.
Example 2
points = [3, 2, 1, 2, 2]tokens = "ETTTE"return = 7Cells 1, 2 and 3 contain tokens. the sum of points in these cells is 5.
Also there are two pairs of adjacent cells with tokens, which results in 2 extra points.
The function should return 7 :)
Example 3
points = [2, 2, 2, 2]tokens = "TTTT"return = 11All cells contain tokens. The function should return 11 :)
Constraints
points and string tokens are of the same length N;N is an integer within [1, 100];points is an integer within the range [1, 1,000];tokens consists only of the characters 'E' and/or 'T'.More Google problems
- Longest Subarray with Sum at Most KOA · Seen Jul 2026
- Count Prefix Matches in a Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Decode StringONSITE INTERVIEW · Seen Jul 2026
- Phone Keypad Letter CombinationsONSITE INTERVIEW · Seen Jul 2026
- Split a Log Outside QuotesONSITE INTERVIEW · Seen Jul 2026
- Ad Score Scheduler With DelayONSITE INTERVIEW · Seen Jul 2026
- Alternating-Color Binary Tree RootsONSITE INTERVIEW · Seen Jul 2026
- Route Pattern MatcherONSITE INTERVIEW · Seen Jul 2026