Amazon Interview Question

Tries and back tracking question