Pergunta de entrevista da empresa Amazon

Question about array traversal using heap and finding substring