Skip to content

Practice Minimum Time to Remove All Cars Containing Illegal Goods

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

Hard#2167
LeetCode Problem

Minimum Time to Remove All Cars Containing Illegal Goods

Problem Statement

Binary s describes train cars; 1 marks illegal goods and 0 marks an empty car. Remove a car from either end for one unit of time, or from any position for two units. Repeat as needed, including removing cars without illegal goods. Return the least total time to remove every 1; an empty train is allowed.

Source: Minimum Time to Remove All Cars Containing Illegal Goods on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "1100101"
Output
5

# Example 2

Input
s = "0010"
Output
2

Constraints

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

Related LeetCode Problems

Practice more problems similar to Minimum Time to Remove All Cars Containing Illegal Goods.

Review your practice with PhantomCodeAI

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