Please check my solution
the value of l is wrong
it should be the maximum value of the given input array