Extreme Networks Interview Question

String traversal and the logic behind it