Skip to content

Practice Number of Ways to Select Buildings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2222
LeetCode Problem

Number of Ways to Select Buildings

Problem Statement

Binary s lists buildings in street order: 0 is an office and 1 is a restaurant. Choose three distinct indices in increasing order so adjacent selected buildings have different types. Return the number of valid choices; selected buildings need not be consecutive on the street.

Source: Number of Ways to Select Buildings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "001101"
Output
6

# Example 2

Input
s = "11100"
Output
0

Constraints

3 <= s.length <= 10^5
s[i] is either '0' or '1'.

Related LeetCode Problems

Practice more problems similar to Number of Ways to Select Buildings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.