#### Given a singly linked list, remove all the nodes which have a greater value on right side.

Example:

The list 12->15->10->11->5->6->2->3->NULL should be changed to 15->11->6->3->NULL. Note that 12, 10, 5 and 2 have been deleted because there is a greater value on the right side. When we examine 12, we see that after 12 there is one node with value greater than 12 (i.e. 15),so we delete 12. When we examine 15, we find no node after 15 that has value greater than 15 so we keep this node. When we go like this, we get 15->6->3

##### In Simple term delete when ith element < (i+1) element

** Algorithm:**

- Base code: when list is empty or one element return list
- Set following pointer
`node = head`

`prev = null`

- Iterate till
`node.next != null`

- if
`node.data < node.next.data`

then do following things- if
`prev == null`

`head = node.next`

`node.next = null`

`node = head<`

- else
`prev.next = node.next`

`node.next = null`

`node= prev.next`

- if
- else
`prev = node`

`node = node.next`

- if

Latest Source Code:

Github: ListRemoveGreaterValueFromRight.java

**Output:**

12 15 10 11 5 6 2 3 15 11 6 3 10 20 30 40 50 60 60