r/programming • • Sep 22 '20

Google engineer breaks down the problems he uses when doing technical interviews. Lots of advice on algorithms and programming.

https://alexgolec.dev/google-interview-questions-deconstructed-the-knights-dialer/
6.4k Upvotes

1.1k comments sorted by

View all comments

3

u/schlenk Sep 22 '20

There should be a closed form solution that runs in constant time. After all, the graph is quite small and fully deterministic, so there must be a repeating pattern once the phase space loops back to a starting position you already know. Once you found the period size for each starting point, a lookup table would work. Might be too memory heavy in the worst case though.

1

u/[deleted] Sep 24 '20 edited Sep 24 '20

I tried that, read my other, longer post here. In summary, if you can take powers of the matrix:

4 1
4 2

in constant time, you win. It is easy to expand the matrix coefficients to the final result in constant time, but taking powers of that core matrix faster than binary exponentiation seems somewhat tricky.