FastPrepFastPrep
Problem Brief

Number of Balanced Strings

FULLTIMEINTERNOA

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.

1Example 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.

2Example 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.

public int numberOfBalancedStrings(int n, int d) {
  // write your code here
}
Input

n

3

d

3

Output

224

Sign in to submit your solution.