iOS

How to flatten a linked list who has down & next pointer

[Question]: Given a linked list where every node represents a linked list and contains two pointers of its type:  Condition: All linked lists are sorted and the resultant linked list should also be sorted

How to rotate linked list with K-th places ?

[Question]: Given the head of a linked list, rotate the list to the right by k places.Example: – Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] #Approach Step: 1 Create tail node which moves till endsStep: 2 Create curr the tail node is the (len-k)-th node (1st node is head)Step: 3 Reorder linked list

How to Reverse a Linked List in groups of given size

[Question]: Given the head of a linked list, reverse the nodes of the list k at a time, and return the updated list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is. …

How to create deep copy of linked list who has random pointer

[Question]: Create a deep copy of the linked list. which consist of exactly n fresh new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent …

How to remove duplicates from a sorted doubly linked list

[Question]: Given a sorted doubly linked list head. Remove duplicate nodes from the given list. #Approach: Step 1: Compare current node item with next node item Step 2: If two items same move next pointer to next’s nextStep 3: If current Node & next Node doesn’t match use node = next

How to find find pairs with given sum in doubly linked list

[Question]: Given a sorted doubly linked list of positive distinct elements, Find pairs in a doubly-linked list whose sum is equal to given value k, without using any extra space?  #Approach. Using two pointer

How to Delete all occurrences of a given key in a doubly linked list

[Question]: Given a doubly linked list and a key x. The problem is to delete all occurrences of the given key x from the doubly linked list. #Approach: we declare two variable prevNode and nxtNode and in a loop if we finds the data value of linklist node is equals to k just break link to the node.