Pregunta de entrevista de Amazon

Question about array traversal using heap and finding substring