Snake Ladder Problem! Time : Space : 123456789101112131415161718192021222324int Solution::snakeLadder(vector<vector<int>> &A, vector<vector<int>> &B) { vector<int> vis(101, -1); queue<int> q; q.push(1); vis[0] = vis[1] = 0; unordered_map<int, int> mp; for(auto vec : A) mp[vec[0]] = vec[1]; for(auto vec : B) mp[vec[0]] = vec[1]; while(q.size()) { auto u = q.front(); q.pop(); for(int i = 1; i <= 6; i++) { if(u + i > 100 or vis[u + i] != -1) continue; vis[u + i] = vis[u] + 1; if(mp.count(u + i)) { if(vis[mp[u + i]] == -1) { q.push(mp[u + i]); vis[mp[u + i]] = vis[u] + 1; } } else q.push(u + i); } } return vis[100];}