Implementation is relatively straight forward, but non-trivial, considering the number of required test cases.