The Score of a String interview question asks you to compute a "score" for a given string. The score is the sum of the absolute differences between the ASCII values of all adjacent character pairs. For example, for "hello", you compute |h-e| + |e-l| + |l-l| + |l-o| and sum those values. This is a simple string traversal and arithmetic problem.
Microsoft, Meta, Amazon, Google, and Bloomberg ask this as a beginner-level warm-up that tests character-to-ASCII conversion, adjacent element comparison, and cumulative sum computation. It validates coding fluency with ord() (or equivalent) and basic loop logic. Despite its simplicity, it distinguishes candidates who write clean, readable code from those who over-complicate straightforward tasks.
The pattern is linear scan with adjacent pair processing. Iterate from index 0 to len(s) - 2. For each index i, compute abs(ord(s[i]) - ord(s[i+1])) and add to the running total. Return the total. In Python, this is elegantly expressed as sum(abs(ord(a) - ord(b)) for a, b in zip(s, s[1:])).
Input: "hello"
Adjacent pairs:
Score = 3 + 7 + 0 + 3 = 13.
Input: "zaz":
Score = 50.
abs().len(s) instead of len(s) - 1, causing an index-out-of-bounds error when accessing s[i+1].>, <) instead of ord() for numeric values.For the Score of a String coding problem, the string interview pattern is the simplest adjacent-pair traversal. In Python, the zip(s, s[1:]) idiom elegantly pairs adjacent characters without index arithmetic. Interviewers at Meta and Google use this as a 2-minute warm-up — solve it instantly with the zip idiom and offer to discuss follow-ups: "What if we wanted the maximum single adjacent difference?" (just use max instead of sum).
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Detect Capital | Easy | Solve | |
| Delete Characters to Make Fancy String | Easy | Solve | |
| Find the Original Typed String I | Easy | Solve | |
| Valid Word | Easy | Solve | |
| Number of Segments in a String | Easy | Solve |