First time participated in monthly Function Programming challenge (the August one). I've decided to pick Python as my favorite programming language. Here you could find the solution I've come with. Have to admit that it's robust, not much mem consuming. For n × m input matrix it takes O(n) memory with O(n × m) algorithm's complexity.
Waiting for Monday to check my solution on new input data.