Not clear with the complexity. As the solution code inserting values at beginning of list at end why that is not considered while complexity analysis. Inserting at front would shift all the element and thus would lead to O(n^2) complexity.
Please help…