Last Updated: 4 Oct, 2020

Remove Nodes

Easy
Asked in company
Samsung

Problem statement

Given a linked list such that each node represents a digit. Remove nodes at the 2^'I -th' position from the linked list where 'I' can be 0, 1, 2, and so on.

Input format :
The first and only line contains the 'N' sized linked list elements separated by space and terminated by -1.
Output format :
The only line of output prints the updated linked list elements separated by a single space.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function and return the answer.
Constraints:
-10^9 <= 'data' <= 10^9

Time Limit: 1 sec

Approaches

01 Approach

Try to traverse with updating the position of the current node from the head and if the position is in integral powers of 2 (use previous power of 2), then just skip that node and make a new link form the previous node to the next of the current node. Always irrespective of the size of the linked list you need to skip the head in the updated linked list.