Problem 4 solution
Problem 5 solution
Problem 6 Solution

Forgot about lexigraphical comparison of arrays. :(