11. Trail of Ones
โ GFG solution to the Trail of Ones problem: count binary strings of length n with at least one pair of consecutive 1's using dynamic programming approach. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: n = 2
Output: 1
Explanation: There are 4 strings of length 2, the strings are 00, 01, 10, and 11.
Only the string 11 has consecutive 1's.Example 2
Input: n = 3
Output: 3
Explanation: There are 8 strings of length 3, the strings are 000, 001, 010, 011, 100, 101, 110 and 111.
The strings with consecutive 1's are 011, 110 and 111.Example 3
๐ Constraints
โ
My Approach
Dynamic Programming Approach
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
๐งโ๐ป Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated