Meta Interview Question

Shortest Snippet. Given a sequence [A, x, x, B, A, x, B], return the shortest sub-sequence for the given query [A, B]. Returns: [A, x, B]

Interview Answer

Anonymous

Jul 28, 2018

First, save all positions for the each character in the query in a hash. Then calculate the minimum difference between positions with two pointers, one for each array.