Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Select Buildings

Try to solve the Number of Ways to Select Buildings problem.

Statement

You are given a binary string s indexed from 00, where each character represents the type of building along a street:

  • s[i] = '0' denotes that the iextthi^{ ext{th}} building is an office.

  • s[i] = '1' denotes that the iextthi^{ ext{th}} building is a restaurant.

You want to select 33 buildings such that no two consecutive chosen buildings are of the same type. That is, you must choose three indices ii, jj, and kk with 0≤i<j<k<0 \leq i < j < k < s.length such that the selected sequence of characters forms either '010' or '101'.

Return the total number of valid ways to select 33 buildings.

Constraints:

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

  • s[i] is either '0' or '1'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Select Buildings

Try to solve the Number of Ways to Select Buildings problem.

Statement

You are given a binary string s indexed from 00, where each character represents the type of building along a street:

  • s[i] = '0' denotes that the iextthi^{ ext{th}} building is an office.

  • s[i] = '1' denotes that the iextthi^{ ext{th}} building is a restaurant.

You want to select 33 buildings such that no two consecutive chosen buildings are of the same type. That is, you must choose three indices ii, jj, and kk with 0≤i<j<k<0 \leq i < j < k < s.length such that the selected sequence of characters forms either '010' or '101'.

Return the total number of valid ways to select 33 buildings.

Constraints:

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

  • s[i] is either '0' or '1'.