FastPrepFilter Isolated Interior Signal Bits

Filter Isolated Interior Signal Bits

SEDEMAC logoSEDEMAC● EasyNEW GRADOA
Learn

Problem statement

Given a binary signal string, replace every interior 1 whose immediate left and right neighbors are both 0 with 0. Determine all replacements from the original signal, so removals are simultaneous. Keep the first and last bits unchanged.

Function

filterIsolatedInteriorBits(signal: String) → String

Examples

Example 1

signal = "01010"return = "00000"

Both interior one bits are isolated in the original signal and are removed simultaneously.

Example 2

signal = "11011"return = "11011"

No one bit has zero-valued neighbors on both sides.

Constraints

  • 1 <= signal.length <= 200000
  • signal[i] is '0' or '1'

More SEDEMAC problems

See SEDEMAC hiring insights
public String filterIsolatedInteriorBits(String signal) {
    // Write your code here.
}
signal"01010"
expected"00000"
Checking account…