Delete nodes having greater value on right | JAVA | GFG POTD | Java Solution | Apna Coding

Published: 29 August 2023
on channel: Apna Coding
21
0

Hello Friends, I love coding. That's why I have created this channel for our improvment Coding skill. If you have better solution so definatly share with us.
I want ask a question. What should be improvment is required and other you can suggest me. Thank you
Delete nodes having greater value on right” is a problem in which we are given a singly linked list and we have to remove all the nodes which have a greater value on the right side. For example, if we have a linked list 12 15 10- 11 5 6 2 3 NULL, then the output should be 15 11 6 3 NULL. This is because 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 a value greater than 12 (i.e. 15), so we delete 12. When we examine 15, we find no node after 15 that has a value greater than 15, so we keep this node. When we go like this, we get 15 6 3.

The problem can be solved using two loops or by reversing the list. The time complexity of the first method is O(n^2) while that of the second method is O(n). You can find more information about this problem and its solutions on GeeksforGeeks
Delete nodes having greater value on right, Java, GFG POTD, Java Solution, Apna Coding, linked list, singly linked list, data structure, algorithm, programming, coding, computer science, computer programming, computer engineering, software engineering, software development, software design patterns, software testing, software architecture, software quality assurance, software maintenance, software project management, software development process models, software development methodologies, software development life cycle (SDLC), agile methodology, scrum methodology, extreme programming (XP), waterfall model, spiral model, rapid application development (RAD), incremental model, V-model (software development), big data analytics and processing tools and techniques for software development and testing.