Facebook | Phone | Shortest string that is not a subsequence of a given string

Anonymous User
4681
Mar 01, 2020
Mar 29, 2020

I was asked this in phone screen for Facebook. Could solve it only by bruteforce/backtracking. Is there any efficient solution to this?

Problem: Given a binary string S, one has to find another binary string which is not a subsequence of S such that its length is minimal and is lexicographically smallest possible.

Example 1:

Input: "00101"
Output: "100"

Example 2:

Input: "1111"
Output: "0"

Example 3:

Input: "00010000"
Output: "11"
Comments (10)