Dijkstra, Miller-Rabin and Caching
This problem requires Dijkstra since it is a Breadth-First Search (BFS) but you always want to dequeue the element with the smallest path-sum first, hence instead of using a queue you'll need to use a priority queue. It also has a twist that it requires you to check for prime numbers along the way. My favorite method (although overkill here) is Miller-Rabin, but even Miller-Rabin leads to Time Limit Exceeded (TLE) hence you'll need to combine it with global caching. HashSet performs better than HashTable from my observation. Even with all that in place, it was still leading to TLE. Reducing the size of the priority queue from 20K to 10K did the trick. Code is down below. Greetings from the Big Island!! ACC. Digit Operations to Make Two Integers Equal - LeetCode You are given two integers n and m that consist of the same number of digits. You can perform the following operations any number of times: Choose any digit from n...