Flipkart Interview Question

Rat and maze problem