4 ms·
Well I would never interview in a style of 'get 5 answers right, you got the job'. So I can't quite tell from your answer :) But yeah that's generally what most
by roel_v 9y ago
Well I would never interview in a style of 'get 5 answers right, you got the job'. So I can't quite tell from your answer :) But yeah that's generally what most working answers would end up like.
One interesting aspect is that in some circumstances (I don't remember the details - one of my colleagues did some tests 10 years ago) it was faster to do it this way (iterate over all cells in order, so better cache locality) but in some it was better to 'draw rectangles' as it were, ie first put in all 1's, then all 2's and so on. Requires no floating point ops but more cache misses (iirc).