The Reverse Degree of a String interview question asks you to compute a "degree" value for a given string. The degree is calculated by: for each character, multiply its 1-based position in the reversed alphabet (so 'z' = 1, 'y' = 2, ..., 'a' = 26) by its 1-based position in the string (1-indexed). Sum all these products and return the total as the degree of the string.
Capgemini includes this as a beginner-level string and simulation screening question. It tests basic string traversal, character arithmetic, and formula application. While straightforward, it distinguishes candidates who can translate a mathematical specification directly into clean code from those who make off-by-one errors or misread the "reversed alphabet" mapping.
The pattern is linear string traversal with character arithmetic. For each character s[i] (0-indexed), compute:
ord('z') - ord(s[i]) + 1 = 123 - ord(s[i]).i + 1.(123 - ord(s[i])) * (i + 1).Sum all contributions and return the total.
String: "ab"
'a' at position 1: reversed alphabet position = 123 - 97 = 26. Contribution: 26 × 1 = 26.'b' at position 2: reversed alphabet position = 123 - 98 = 25. Contribution: 25 × 2 = 50.Degree = 26 + 50 = 76.
String: "z":
'z' at position 1: reversed alphabet = 123 - 122 = 1. Contribution: 1 × 1 = 1. Degree = 1.ord('a') - ord(s[i]) + 1 (forward alphabet) instead of the reversed alphabet formula.'z'=1, 'y'=2, ..., 'a'=26, not 'a'=1, 'b'=2.For the Reverse Degree of a String coding problem, the string and simulation interview pattern is straightforward. The key formula: reversed_pos = 123 - ord(char) (where 123 = ord('z') + 1). Practice computing this for a few characters on paper to verify correctness before coding. Capgemini interviewers use this as a quick sanity check for code accuracy — solve it in under 3 minutes and double-check your formula derivation.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Calculate Digit Sum of a String | Easy | Solve | |
| Divide a String Into Groups of Size k | Easy | Solve | |
| Faulty Keyboard | Easy | Solve | |
| Generate Tag for Video Caption | Easy | Solve | |
| Minimum Number of Chairs in a Waiting Room | Easy | Solve |