committing Question1-3 solution + my own initial O(n^2) algorithm