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

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-03-01Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

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