Tap here to switch tabs
Problem
Submissions

Problem: Number of Times Binary String Is Prefix-Aligned

med
30 min
Try to solve the Number of Times Binary String Is Prefix-Aligned problem.

Statement

You are given a binary string of length n where all characters are initially $0$, indexed from $1$ to n.

At each step i from $1$ to n, the character at the $1$ based index flips[i - 1] is flipped to $1$.

A binary string is considered prefix aligned at step i if every character from index $1$ to i is $1$ and all other characters from index i + 1 to n are $0$.

Return the total number of steps at which the binary string is prefix aligned.

Constraints:

  • n is equal to flips.length

  • 1≤1 \leq n ≤5imes104\leq 5 imes 10^4

  • flips is a permutation of the integers in the range [1,[1, n]]

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Times Binary String Is Prefix-Aligned

med
30 min
Try to solve the Number of Times Binary String Is Prefix-Aligned problem.

Statement

You are given a binary string of length n where all characters are initially $0$, indexed from $1$ to n.

At each step i from $1$ to n, the character at the $1$ based index flips[i - 1] is flipped to $1$.

A binary string is considered prefix aligned at step i if every character from index $1$ to i is $1$ and all other characters from index i + 1 to n are $0$.

Return the total number of steps at which the binary string is prefix aligned.

Constraints:

  • n is equal to flips.length

  • 1≤1 \leq n ≤5imes104\leq 5 imes 10^4

  • flips is a permutation of the integers in the range [1,[1, n]]