Bloomberg Interview Question: Generate All Binary Strings from Wildcards

10 Views
No Comments
Implement a procedure that will print out all permutations of a given binary string 
that may or may not contain one or more "wildcards".

Consider a "binary string" such as:
"0110"

Now imagine we swap a character in this string for a "wildcard" (represented by "?")
"01?0"

For the purposes of this question, we say a "wildcard" evaluates to one of two possible 
values: "0" or "1".

If your method is passed a binary string with one or more wildcards, it should print out 
all possible permutations of that string with the wildcard.

e.g.
"0?1" --> "001" "011"

This problem asks you to recursively or iteratively expand all ? positions in a binary string, producing every valid 0/1 combination. Each wildcard branches into two possibilities. A depth-first search (DFS) is the most natural solution.


Bloomberg Interview Question: Maximum Travel Distance on a Circular Moon Route

You wish to send a research rover to survey the equator of a small moon.
Fuel has been dropped along the desired route by previous missions, and you can choose 
to drop your rover at any starting point on the route.

Each unit of fuel can move the rover 1 mile.
Given the location and volume of each fuel drop as well as the circumference of the moon, 
find the farthest distance your rover can travel before running out of fuel.

The rover can only travel in one direction (east).

The input consists of tuples (distance east from first fuel drop, amount of fuel) 
and the circumference.

Input:
fuel_drops = [(0, 20), (20, 10), (60, 40)]
circumference = 100

Expected output: 70

# Explanation:
# Start at 60  (location: 60, fuel reserves: 40)
# Drive for 40  (location: 100|0, fuel reserves: 0)
# Refuel at 0   (location: 100|0, fuel reserves: 20)
# Drive for 20  (location: 20, fuel reserves: 0)
# Refuel at 20  (location: 20, fuel reserves: 10)
# Drive for 10  (location: 30, fuel reserves: 0)

This is a circular route fuel-management problem. You may start at any fuel drop. As you travel east, you consume fuel and pick up any fuel supplies you reach. Your goal is to find the starting point that maximizes total reachable distance before fuel depletion. The problem resembles finding the optimal starting index in a circular gas-station challenge.

END
 0