Tap here to switch tabs
Problem
Submissions

Problem: Number of Substrings With Fixed Ratio

Try to solve the Number of Substrings With Fixed Ratio problem.

Statement

You are given a binary string s and two integers num1 and num2.

A substring of s is considered valid if the ratio of the number of $0$s to the number of $1$s in the substring is equal to num1 to num2.

Return the total number of non empty valid substrings of s.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq num1, num2 ≤\leq s.length

  • num1 and num2 are coprime integers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Substrings With Fixed Ratio

Try to solve the Number of Substrings With Fixed Ratio problem.

Statement

You are given a binary string s and two integers num1 and num2.

A substring of s is considered valid if the ratio of the number of $0$s to the number of $1$s in the substring is equal to num1 to num2.

Return the total number of non empty valid substrings of s.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq num1, num2 ≤\leq s.length

  • num1 and num2 are coprime integers.