assignment 7 - add O(mn) algorithm to problem 3