You are given a string num. A string of digits is called balanced if the sum of the digits at even indices is equal to the sum of the digits at odd indices.
Return the number of distinct permutations of num that are balanced.
Since the answer may be very large, return it modulo 109 + 7.
A permutation is a rearrangement of all the characters of a string.
Examples
Example 1
Input: num = "123"
Output: 2
Explanation:
Example 2
Input: num = "112"
Output: 1
Explanation:
Example 3
Input: num = "12345"
Output: 0
Explanation:
Constraints
2 <= num.length <= 80
num consists of digits '0' to '9' only.
3343. Count Number of Balanced Permutations
Hard
50 Points
Math
String
Dynamic Programming
Combinatorics
You are given a string num. A string of digits is called balanced if the sum of the digits at even indices is equal to the sum of the digits at odd indices.
Return the number of distinct permutations of num that are balanced.
Since the answer may be very large, return it modulo 109 + 7.
A permutation is a rearrangement of all the characters of a string.
Examples
Example 1
Input: num = "123"
Output: 2
Explanation:
Example 2
Input: num = "112"
Output: 1
Explanation:
Example 3
Input: num = "12345"
Output: 0
Explanation:
Constraints
2 <= num.length <= 80
num consists of digits '0' to '9' only.
Count Number of Balanced Permutations - Practice Coding | SlaveCode