since you use splice when inserting an element to the list, it takes O(n) time.
since you use splice when inserting an element to the list, it takes O(n) time.