Cpp, Cplusplus, Programming, Software Development, Interview Questions.
while (!q.empty()) { auto current = q.front(); q.pop(); // The first time we visit the end coordinate // is the shortest path if (current.row == std::ssize(grid)-1 && current.col == std::ssize(grid[current.row])-1) { return current.distance; } // For every direction, try to move there for (auto dir