Good Strings

Problem Overview

  • Count the number of length-n lowercase strings where the absolute difference between adjacent letters (a–z) is at most d.
  • Input: integers n and d; Output: count of Good Strings modulo 1e9+7.
  • Constraints: n ≤ 1e5, d ≤ 25; letters differ by 0–25 (e.g., a–z is 25, b–c is 1).
  • Real-world domain: string validation/counting over the English alphabet.
  • Mathworks interviews: a coding interview interview question and counting problem.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: