Add Before In Doubly Linkedlist
Try First, Check Solution later1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.
1. You are given a partially written DoublyLinkedList class.Input Format
2. You are required to complete the body of addBefore function. This function is supposed to add value before given Node.
3. If size of list is zero then return "ListIsEmpty: -1".
4. If Index is Invalid then return "IndexIsInValid: -1".
5. You are required to update head, tail and size as required.
6. Input and Output is managed for you. Just update the code in incomplete function.
Note -> Use the code snippet and follow the algorithm discussed in question video. The judge can't
force you but the intention is to teach a concept. Play in spirit of the question.
input in managed for you.Output Format
output in managed for you.Question Video
0 <= N <= 10^6Sample Input
addFirst 4Sample Output
getAt 4 3
addAt 4 34
addAt 0 43
addBefore 2 33
addBefore 0 33
addBefore 4 33
addAt 8 545
addAt 0 345
[345, 4, 34]
Asked in Companies