eBay Interview Question

Question on graphs and strings