← Flipkart questions

Shortest path in graph with GCD edge condition

Filed under Flipkart

Consider a graph with n <= 1e5 nodes where an edge exists between i and j if gcd(i, j) > k for a given integer k >= 0. Given q queries, find the shortest path between two given nodes or return -1.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Flipkart questions

Collected from public candidate posts and coding forums. Updated Nov 2026.