Shrink an index, a number, or a range
Choose parameters that describe remaining work without copying it.
Understand the idea
An index can identify an unprocessed array suffix. Two indices can identify an untested string interval. For a nonnegative integer, division by 10 removes its final digit. Keep the original container by reference when recursive calls only need different boundaries.
Trace a small example
A palindrome test on racecar compares positions 0 and 6, then 1 and 5, then 2 and 4; meeting at position 3 succeeds. Digit sum on 407 returns 7 + 0 + 4. Treat zero deliberately: a sum of digits can return 0, while printing digits must still print one zero.
Conditions and cost
Repeated substring copying can turn a linear traversal into quadratic copying work. Every branch must make progress. Signed values need a stated normalization policy; taking abs of the most negative signed integer may not fit.
Which parameters avoid repeatedly copying a string during palindrome testing?
Turn the idea into code
Explain the recursive steps for the digit sum of 1002.
Give me a hint
Use n % 10 and n / 10.
Show the explained solution
The terms are 2, 0, 0, and 1; their sum is 3. Internal zeros are visited even though they add nothing.
Your notes
Mark complete when you can explain it yourself.