Note - I am not sure whether this question belongs to code review SE or CS stackexchange or here
Given a list Lconsisting of n
L