Count of Binary Strings possible as per given conditions

Given two integers N and M, where N denotes the count of ‘0’ and M denotes the count of ‘1’, and an integer K, the task is to find the maximum number of binary strings that can be generated of the following two types:

  • A string can consist of K0‘s and a single ‘1‘.
  • A string can consist of K1‘s and a single ‘0‘.

Examples:

Input: N = 4, M = 4, K = 2
Output: 6
Explanation:
Count of ‘0‘s = 4
Count of ‘1‘s = 4
Possible ways to combine 0’s and 1’s under given constraints are {“001”, “001”} or {“001”, “110”} or {“110”, “110”}
Therefore, at most 2 combinations exists in a selection.
Each combination can be arranged in K + 1 ways, i.e. “001” can be rearranged to form “010, “100” as well.
Therefore, the maximum possible strings that can be generated is 3 * 2 = 6

Input: N = 101, M = 231, K = 15
Output: 320

Approach:
Follow the steps below to solve the problem: