MoveworksOA #2
Number of Balanced Strings
Estimated MediumStatement and editorial — judging is being prepared
Topics (AI-labelled)DP Basics
Write a Java program with a function named numberOfBalancedStrings that counts the number of ways we can make a balanced string of size n and difference d.
A Balanced string is a string where the difference between adjacent characters does not exceed d.
Constraints
N/A
Example 1
Input:
n = 3
d = 3
Output:
224
Explanation: There are 224 ways to create a balanced string of size 3 with a maximum adjacent character difference of 3.
Example 2
Input:
n = 2
d = 2
Output:
124
Explanation: There are 124 ways to create a balanced string of size 2 with a maximum adjacent character difference of 2.
Editorial
Loading solution…