Today I've learned that I should apply my interview tools
- can I relax some of the contraints on the result?
- can I approach it in more time / more space?
- can I assume I have crucial functions that would lead me towards a solution?
everytime I get stuck. Even when I'm baffled by the complexity of a problem: for example today I was given a mathematical problem, that was presented more or less like:
You are given
f(x) = ( a * ( b - x ) ) % m
, how would you go and implement a function that tells you the length of the repeating sequence?
So, the key points here are two:
f(x) = ( a * ( b - x ) ) % m
could be simplified asf(x) = x % m
%
works like this0 % 3 == 0
,1 % 3 == 1
,2 % 3 == 0
,3 % 3 == 0
,4 % 3 == 1
it is clear now that %
repeats a sequence. So that was the key to go through the problem.
I've been asked to show how I would implement an url shortener, I feel like it went better than the last time. Last time it was in an interview, I think 1.5 years ago, so many thing changed since then.