Problem of the day
You are given the head of a linked list ‘list’ of size ‘N’.
Your task is to delete the linked list's last node and return the linked list's head.
Input: ‘N’ = 4, ‘list’ = 4 -> 2 -> 5 -> 1
Output: 4 2 5
Explanation:
After deleting the last node, the Linked List is 4 -> 2 -> 5.
The first line contains one integer, ‘N’, denoting the size of the linked list ‘list’.
The following line contains ‘N’ integers, denoting the elements of the ‘list’.
Return the head of the new linked list.
You don't need to print anything. Just implement the given function. Contents of your returned linked list will be printed.
4
4 2 5 1
4 2 5
Input: ‘N' = 4, ‘list’ = 4 -> 2 -> 5 -> 1
Output: 4 2 5
Explanation:
After deleting the last node, the Linked List is 4 -> 2 -> 5.
5
4 3 2 1 5
4 3 2 1
Input: ‘N’ = 5, ‘list’ = 4 -> 3 -> 2 -> 1 -> 5
Output: 4 3 2 1
Explanation:
After deleting the last node, the Linked List is 4 -> 3 -> 2 -> 1.
Try solving this in O(N).
2 <= 'N' <= 10^4
0 <= list elements <= 10^5
Time Limit: 1 sec