question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reverse-linked-list | Rust 100% | rust-100-by-astroex-6d68 | \nimpl Solution {\n pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let (mut prev, mut curr) = (None, head);\n wh | astroex | NORMAL | 2021-09-21T20:42:30.430379+00:00 | 2021-09-21T20:55:24.980455+00:00 | 1,901 | false | ```\nimpl Solution {\n pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let (mut prev, mut curr) = (None, head);\n while let Some(mut node) = curr {\n curr = node.next;\n \n node.next = prev;\n \n prev = Some(node);\n ... | 38 | 0 | ['Rust'] | 6 |
reverse-linked-list | O( n )✅ | Recursive approach✅ | Python (Step by step explanation)✅ | o-n-recursive-approach-python-step-by-st-zsas | Intuition\nThe code aims to reverse a singly-linked list. It utilizes a recursive approach to achieve this.\n\n# Approach\nThe approach used in the code is a re | monster0Freason | NORMAL | 2023-10-30T18:12:35.171832+00:00 | 2023-10-31T11:38:38.924464+00:00 | 2,263 | false | # Intuition\nThe code aims to reverse a singly-linked list. It utilizes a recursive approach to achieve this.\n\n# Approach\nThe approach used in the code is a recursive algorithm for reversing a singly-linked list. The code defines a function `reverseList` that takes the head of the linked list as input. It proceeds a... | 37 | 0 | ['Linked List', 'Recursion', 'Python3'] | 2 |
reverse-linked-list | Very Easy and Fast Python Solution | very-easy-and-fast-python-solution-by-kh-7xxi | \nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n prev=None\n while(head):\n nxt=head.nex | Khan_Baba | NORMAL | 2022-10-17T18:06:26.969030+00:00 | 2022-10-19T13:55:55.262120+00:00 | 4,473 | false | ```\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n prev=None\n while(head):\n nxt=head.next\n head.next=prev\n prev=head\n head=nxt\n return prev\n \n```\n\n**Explanation**\nOne think to keep in m... | 36 | 0 | ['Iterator'] | 5 |
reverse-linked-list | Very Very Easy C++ code | very-very-easy-c-code-by-thekalyan001-ynyz | Upvote if you liked it\n\n\nListNode* reverseList(ListNode* head) {\n ListNode *b=NULL,*c=NULL;\n \n while(head!=NULL)\n {\n | thekalyan001 | NORMAL | 2021-09-20T15:48:39.830558+00:00 | 2021-09-20T15:49:08.787600+00:00 | 2,878 | false | Upvote if you liked it\n\n```\nListNode* reverseList(ListNode* head) {\n ListNode *b=NULL,*c=NULL;\n \n while(head!=NULL)\n {\n c=b;\n b=head;\n head=head->next;\n b->next=c;\n }\n return b;\n \n }\n``` | 36 | 2 | ['C'] | 3 |
reverse-linked-list | JavaScript solution (both iterative and recursive) | javascript-solution-both-iterative-and-r-m5m4 | \n\n function reverseList(head) {\n var prev = null;\n while (head) {\n var next = head.next;\n head.next = prev;\n | linfongi | NORMAL | 2016-05-04T03:30:16+00:00 | 2018-09-28T02:30:46.464718+00:00 | 5,089 | false | \n\n function reverseList(head) {\n var prev = null;\n while (head) {\n var next = head.next;\n head.next = prev;\n prev = head;\n head = next;\n }\n return prev;\n }\n \n \n function reverseList(head) {\n if (!head || !head.n... | 34 | 1 | [] | 4 |
reverse-linked-list | 8ms Golang solution | 8ms-golang-solution-by-linfongi-rp3y | func reverseList(head *ListNode) *ListNode {\n \tvar prev *ListNode\n \tfor head != nil {\n \t\thead.Next, prev, head = prev, head, head.Next\n \t}\ | linfongi | NORMAL | 2016-03-28T05:17:46+00:00 | 2016-03-28T05:17:46+00:00 | 2,808 | false | func reverseList(head *ListNode) *ListNode {\n \tvar prev *ListNode\n \tfor head != nil {\n \t\thead.Next, prev, head = prev, head, head.Next\n \t}\n \treturn prev\n } | 32 | 0 | ['Go'] | 3 |
reverse-linked-list | 🌟Best Solution Ever! 🚀 Python|| Java|| C++|| C|| JavaScript|| Go|| C#....... 💻🌟 | best-solution-ever-python-java-c-javascr-upma | 🌀 IntuitionReversing a linked list involves flipping the direction of the links between the nodes. Instead of having each node point to the next node, we revers | alantomanu | NORMAL | 2025-01-06T17:39:04.691030+00:00 | 2025-01-11T12:32:05.551166+00:00 | 5,675 | false | # 🌀 Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Reversing a linked list involves flipping the direction of the links between the nodes. Instead of having each node point to the next node, we reverse the pointers so that each node points to the previous node.
---
# 🛠️ Approach
<!-- ... | 31 | 0 | ['Linked List', 'Swift', 'C++', 'Java', 'Go', 'TypeScript', 'Python3', 'Kotlin', 'JavaScript'] | 8 |
reverse-linked-list | Python iterative and recursive solution, both O(n) time complexity. | python-iterative-and-recursive-solution-mqhtx | # Iteratively\n def reverseList1(self, head):\n node = None\n while head:\n tmp = head.next\n head.next = node\n | oldcodingfarmer | NORMAL | 2015-07-15T13:34:12+00:00 | 2015-07-15T13:34:12+00:00 | 7,041 | false | # Iteratively\n def reverseList1(self, head):\n node = None\n while head:\n tmp = head.next\n head.next = node\n node = head\n head = tmp\n return node\n \n # Recursively \n def reverseList(self, head):\n return self.helper(head... | 31 | 0 | ['Recursion', 'Iterator', 'Python'] | 2 |
reverse-linked-list | Reverse Linked List || Easy recursive solution with image explanation | reverse-linked-list-easy-recursive-solut-y5nk | Easy C++ solution--->\n Let us take an example->\n \n \n\n1) reverseByRecursion(node1) is called.\n2) Neither node1 nor node1->next is NULL, so newHead = revers | rawat_abhi33 | NORMAL | 2022-06-03T07:06:59.079965+00:00 | 2022-06-03T07:08:14.152878+00:00 | 2,283 | false | Easy C++ solution--->\n Let us take an example->\n \n \n\n1) reverseByRecursion(node1) is called.\n2) Neither node1 nor node1->next is NULL, so newHead = reverseList(head2); is called.\n3) Neither node2 nor node... | 30 | 0 | ['Linked List', 'Recursion', 'C', 'C++'] | 7 |
reverse-linked-list | Fast Recursive Java solution | fast-recursive-java-solution-by-second_x-l94w | public class Solution {\n public ListNode reverseList(ListNode head) {\n if(head == null ||head.next == null){\n return head;\n | second_xia | NORMAL | 2015-10-14T07:34:33+00:00 | 2015-10-14T07:34:33+00:00 | 7,693 | false | public class Solution {\n public ListNode reverseList(ListNode head) {\n if(head == null ||head.next == null){\n return head;\n }\n \n ListNode root = reverseList(head.next);\n \n head.next.next = head;\n head.next = ... | 30 | 0 | [] | 2 |
reverse-linked-list | Easy Solution | | Optimal Solution | | C++ | | Java | | Python3 | | Kotlin | | ✅✅✅🔥🔥 | easy-solution-optimal-solution-c-java-py-b04c | \n\n## Intuition\nTo reverse a singly linked list, we can iterate through the list while maintaining pointers to the previous, current, and next nodes. During e | Hunter_0718 | NORMAL | 2024-03-21T00:05:53.805121+00:00 | 2024-03-21T00:15:00.328850+00:00 | 9,180 | false | \n\n## Intuition\nTo reverse a singly linked list, we can iterate through the list while maintaining pointers to the previous, current, and next nodes. During each iteration, we update the `next` pointer of... | 29 | 0 | ['Linked List', 'C++', 'Java', 'Python3', 'Kotlin', 'JavaScript'] | 4 |
reverse-linked-list | C++ / Python simple iterative solution | c-python-simple-iterative-solution-by-to-dm82 | C++ :\n\n\nListNode* reverseList(ListNode* head) {\n\tListNode *nextNode, *prevNode = NULL;\n\twhile (head) {\n\t\tnextNode = head->next;\n\t\thead->next = prev | TovAm | NORMAL | 2021-10-10T11:04:57.419141+00:00 | 2021-10-10T11:04:57.419174+00:00 | 4,067 | false | **C++ :**\n\n```\nListNode* reverseList(ListNode* head) {\n\tListNode *nextNode, *prevNode = NULL;\n\twhile (head) {\n\t\tnextNode = head->next;\n\t\thead->next = prevNode;\n\t\tprevNode = head;\n\t\thead = nextNode;\n\t}\n\treturn prevNode;\n}\n```\n\n**Python :**\n\n```\ndef reverseList(self, head: Optional[ListNode]... | 28 | 0 | ['C', 'Python', 'C++', 'Python3'] | 4 |
reverse-linked-list | 0ms 100% Faster 100% less memory | 0ms-100-faster-100-less-memory-by-sreeje-muf4 | Iterative solution\nLanguage: Go\nSpeed: 0ms\nMemory: 2.5 MB\n\nfunc reverseList(head *ListNode) (prev *ListNode) {\n\tfor head != nil {\n\t\thead.Next, prev, h | sreejeet | NORMAL | 2020-05-22T17:56:59.057360+00:00 | 2020-05-22T17:56:59.057414+00:00 | 1,780 | false | Iterative solution\nLanguage: Go\nSpeed: 0ms\nMemory: 2.5 MB\n```\nfunc reverseList(head *ListNode) (prev *ListNode) {\n\tfor head != nil {\n\t\thead.Next, prev, head = prev, head, head.Next\n\t}\n\treturn\n}\n\n``` | 28 | 0 | ['Go'] | 2 |
reverse-linked-list | Iteratively and recursively Java Solution | iteratively-and-recursively-java-solutio-rd92 | \tpublic class Solution {\n\t public ListNode reverseList(ListNode head) {\n\t \tif(head == null) return head;\n\t \t\n\t \tListNode next = head.nex | syftalent | NORMAL | 2015-05-29T04:22:19+00:00 | 2015-05-29T04:22:19+00:00 | 9,265 | false | \tpublic class Solution {\n\t public ListNode reverseList(ListNode head) {\n\t \tif(head == null) return head;\n\t \t\n\t \tListNode next = head.next;\n\t \thead.next = null;\n\t \n\t \twhile(next != null){\n\t \tListNode temp = next.next;\n\t \tnext.next = head;\n\t \thead... | 28 | 0 | ['Java'] | 2 |
reverse-linked-list | C# Shortest & Fastest Iterative Solution. Time: O(n)❤ | c-shortest-fastest-iterative-solution-ti-577a | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | Din_Srg | NORMAL | 2023-01-24T05:52:13.337882+00:00 | 2023-06-19T05:57:27.445683+00:00 | 3,562 | false | # Complexity\n- **Time complexity**: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- **Space complexity**: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic ListNode ReverseList(ListNode head)\n{\n ListNode resultNode = null;\n while(head != null)\n {\... | 27 | 0 | ['Linked List', 'C#'] | 6 |
reverse-linked-list | The simplest way on javascript | the-simplest-way-on-javascript-by-kathan-2a8z | var reverseList = function(head){\n \n var tmp = null;\n var newHead = null;\n while(head !== null){\n tmp = head;\n head = he | kathandra | NORMAL | 2015-05-28T23:45:11+00:00 | 2018-10-25T22:16:06.607267+00:00 | 5,479 | false | var reverseList = function(head){\n \n var tmp = null;\n var newHead = null;\n while(head !== null){\n tmp = head;\n head = head.next;\n tmp.next = newHead;\n newHead = tmp;\n }\n \n return newHead;\n } | 26 | 0 | ['JavaScript'] | 5 |
reverse-linked-list | Java iterative 0ms solution with explanation | java-iterative-0ms-solution-with-explana-es34 | This seems to be a classic question that I have received multiple times in real interviews. Typically, it is asked as a phone screen or initial screening quest | bdwalker | NORMAL | 2016-02-12T20:50:53+00:00 | 2016-02-12T20:50:53+00:00 | 9,805 | false | This seems to be a classic question that I have received multiple times in real interviews. Typically, it is asked as a phone screen or initial screening questions. Regardless, it can seem a bit tricky but it really doesn't take a whole lot of code to accomplish this. \n\nMy solution is as follows:\n\n public Lis... | 26 | 2 | [] | 4 |
reverse-linked-list | very easy to understand in python | very-easy-to-understand-in-python-by-raj-ytfa | \n\n \n\nref :: https://learnersbucket.com/examples/algorithms/learn-how-to-reverse-a-linked-list/ \n\n\n# Definition for singly-linked list.\n# class ListNode | rajitkumarchauhan99 | NORMAL | 2022-08-18T17:10:26.633345+00:00 | 2022-08-23T14:34:37.068531+00:00 | 3,569 | false | \n\n \n\nref :: https://learnersbucket.com/examples/algorithms/learn-how-to-reverse-a-linked-list/ \n\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\... | 25 | 0 | ['Python', 'Python3'] | 5 |
reverse-linked-list | [Python] 2 pointers solution, explained | python-2-pointers-solution-explained-by-3e11x | The idea is to keep 2 pointers for current and next node and then iterate through nodes and reconnect nodes. The best way to understand this solution is to take | dbabichev | NORMAL | 2021-09-07T07:20:42.681156+00:00 | 2021-09-07T07:20:42.681201+00:00 | 812 | false | The idea is to keep `2` pointers for current and next node and then iterate through nodes and reconnect nodes. The best way to understand this solution is to take some small list, for example `1 -> 2 -> 3 -> 4 -> None` and see what is going on on the each step.\n\n1. In the beginning `curr = None, nxt = 1`.\n2. On the ... | 24 | 3 | ['Linked List', 'Two Pointers'] | 0 |
reverse-linked-list | Python Recursion [Highly Commented] (>99%) | python-recursion-highly-commented-99-by-vcvzm | Standard recursive approach. Traverse to end of linked list with recursive calls. Now orig_head is end node, and head is the node before that. Then swap nodes a | stephenlalor | NORMAL | 2020-05-02T21:05:33.859186+00:00 | 2020-05-02T21:05:33.859235+00:00 | 3,032 | false | Standard recursive approach. Traverse to end of linked list with recursive calls. Now ```orig_head``` is end node, and head is the node before that. Then swap nodes at each step and finally return the ```orig_head``` as the ```head``` of the reversed linked list.\n``` \nclass Solution:\n def reverseList(self, head: ... | 24 | 2 | ['Recursion', 'Python'] | 1 |
reverse-linked-list | My 0ms 10 line java solution | my-0ms-10-line-java-solution-by-peter73-i6hv | public ListNode reverseList(ListNode head) {\n ListNode curr = null;\n ListNode temp = head;\n ListNode prev = null;\n while(temp != | peter73 | NORMAL | 2016-01-04T21:07:08+00:00 | 2016-01-04T21:07:08+00:00 | 4,204 | false | public ListNode reverseList(ListNode head) {\n ListNode curr = null;\n ListNode temp = head;\n ListNode prev = null;\n while(temp != null){\n prev = curr;\n curr = temp;\n temp = curr.next;\n curr.next = prev;\n }\n return curr; \... | 24 | 0 | ['Java'] | 1 |
reverse-linked-list | ✅ 🔥 0 ms Runtime Beats 100% User confirm 🔥|| Step By Steps Solution ✅ || Beginner Friendly ✅ | | 0-ms-runtime-beats-100-user-confirm-step-xjaa | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Problem Intuition :\nReversing a singly linked list means rearranging the next point | Letssoumen | NORMAL | 2024-11-19T02:42:57.880177+00:00 | 2024-11-19T02:42:57.880199+00:00 | 2,856 | false | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Problem Intuition :\nReversing a singly linked list means rearranging the `next` pointers of each node to point to the previous node instead of the next. This operation should be done **in-place** to optimize space usage.\n\n---\n\n### Optimal ... | 23 | 0 | ['Linked List', 'Recursion', 'C++', 'Java', 'Python3'] | 2 |
reverse-linked-list | ✅Simple recursive C# solution | O(n) time | O(n) space✅ | simple-recursive-c-solution-on-time-on-s-ejtc | This solution uses a recursive function to reverse a singly linked list. It starts at the head of the list and follows the next links until it reaches the end o | shukhratutaboev | NORMAL | 2022-12-28T07:05:46.166726+00:00 | 2023-02-04T11:36:09.375097+00:00 | 3,355 | false | This solution uses a recursive function to reverse a singly linked list. It starts at the head of the list and follows the next links until it reaches the end of the list. Then it reverses the next links back to the head of the list, building the reversed list as it goes. When it reaches the head of the original list a... | 23 | 0 | ['Linked List', 'Recursion', 'C#'] | 2 |
reverse-linked-list | javascript | javascript-by-yinchuhui88-lguy | \nvar reverseList = function(head) {\n let pre = null\n while(head){\n const next = head.next\n head.next = pre\n pre = head\n | yinchuhui88 | NORMAL | 2018-12-29T07:14:56.408393+00:00 | 2018-12-29T07:14:56.408490+00:00 | 5,485 | false | ```\nvar reverseList = function(head) {\n let pre = null\n while(head){\n const next = head.next\n head.next = pre\n pre = head\n head = next\n }\n return pre\n};\n``` | 22 | 0 | [] | 6 |
reverse-linked-list | Simplest solution | C# | +98.8% efficient | simplest-solution-c-988-efficient-by-bay-6tr0 | Intuition & Approach\n Describe your first thoughts on how to solve this problem. \nUsing 3 pointers - current, previous and next, we\'ll simply re-link the nod | Baymax_ | NORMAL | 2023-06-06T07:09:10.302296+00:00 | 2023-06-06T07:09:10.302337+00:00 | 2,168 | false | # Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing 3 pointers - current, previous and next, we\'ll simply re-link the nodes to reverse the linked list.\n\n,Θ(1) Recursive & Iterative Solutions Explained | thnth1-recursive-iterative-solutions-exp-c9st | There are multiple possible approaches to solving this problem. In this post, I have outlined 4 approaches that are either the most performant or most mathemati | mxweaver | NORMAL | 2023-04-30T10:55:45.253521+00:00 | 2023-05-12T20:04:17.126960+00:00 | 2,472 | false | There are multiple possible approaches to solving this problem. In this post, I have outlined 4 approaches that are either the most performant or most mathematically interesting.\n\n# Impure Recursive\n\nTo reverse the list with recursion:\n\n- Add an optional parameter to keep track of the parent node\n- If the curren... | 21 | 0 | ['TypeScript'] | 4 |
reverse-linked-list | JS iterative solution with comments | js-iterative-solution-with-comments-by-m-ld3f | \n// Time Complexity: O(n), Linear - traverse linked list only once\n// Space Complexity: O(1), Constant - we will only have 2 pointers regardless of size of in | mrbanh | NORMAL | 2019-08-30T20:35:00.966679+00:00 | 2019-08-30T20:35:00.966717+00:00 | 2,757 | false | ```\n// Time Complexity: O(n), Linear - traverse linked list only once\n// Space Complexity: O(1), Constant - we will only have 2 pointers regardless of size of input; prev and temp\n\nvar reverseList = function(head) {\n // End of the reversed linked list set to null\n let prev = null;\n \n // Traverse thr... | 19 | 0 | ['JavaScript'] | 0 |
reverse-linked-list | C++ | 2 Short O(n) Code | Iterative + Recursive | Easy Code | c-2-short-on-code-iterative-recursive-ea-c5bi | Approach 1: Iterative\n\nclass Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n ListNode *pre = NULL, *cur = head, *nex;\n \n | blazeyp | NORMAL | 2021-10-03T12:18:53.628473+00:00 | 2021-10-03T12:18:53.628504+00:00 | 2,202 | false | **Approach 1: Iterative**\n```\nclass Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n ListNode *pre = NULL, *cur = head, *nex;\n \n while(cur != NULL){\n nex = cur->next;\n cur->next = pre;\n pre = cur;\n cur = nex;\n }\n ... | 18 | 0 | ['Recursion', 'C', 'Iterator', 'C++'] | 1 |
reverse-linked-list | ✅ Animated Solution - 3 Approach - Recursion , Two Pointer | animated-solution-3-approach-recursion-t-pp59 | Interview []\nIf you get this question in your interview and you haven\'t solve this\nit\'s less possible to comeup with 3rd approach and to be honest questions | cs_iitian | NORMAL | 2024-03-21T03:36:51.377895+00:00 | 2024-03-24T17:16:48.862756+00:00 | 1,634 | false | ```Interview []\nIf you get this question in your interview and you haven\'t solve this\nit\'s less possible to comeup with 3rd approach and to be honest questions\non Binary Tree and Linked List are mostly asked that you have already\nseen, I mean there is very less variety available until and unless\ninterview himsel... | 17 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 2 |
reverse-linked-list | beats 100%||Easy reverse Linked List||Explain with figure | beats-100easy-reverse-linked-listexplain-c9j0 | Intuition\n Describe your first thoughts on how to solve this problem. \nExercise for reverse Linked List.\n# Approach\n Describe your approach to solving the p | anwendeng | NORMAL | 2024-03-21T01:57:11.019838+00:00 | 2024-03-21T06:19:51.460123+00:00 | 5,350 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nExercise for reverse Linked List.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTransverse the ListNode with pointer cur.\nUse 2 extra pointers prev & Next to reverse the Linked List.\n$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 17 | 0 | ['Java'] | 1 |
reverse-linked-list | 206: Space Beats 99.79%, Solution with step by step explanation | 206-space-beats-9979-solution-with-step-e7m03 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTo reverse a singly linked list, we need to change the pointers of each n | Marlen09 | NORMAL | 2023-02-23T20:17:41.484332+00:00 | 2023-02-23T20:17:41.484362+00:00 | 4,680 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo reverse a singly linked list, we need to change the pointers of each node to point to the previous node instead of the next node.\n\nWe can start by initializing three pointers:\n\n- prev: a pointer to the previous node, ... | 17 | 0 | ['Linked List', 'Recursion', 'Python', 'Python3'] | 1 |
reverse-linked-list | Super Ez Python Solution ➕ graph Explanation!!! | two pointers | Faster than 93%✅ | super-ez-python-solution-graph-explanati-mff6 | \u628Acur.next\u5B58\u5230nextnode\u4E2D\uFF0C\u9632\u6B62\u65AD\u5F00\u540E\u627E\u4E0D\u5230\nStore cur.next in nextnode, because we will disconnect the cur-> | sophiel625 | NORMAL | 2022-06-21T21:51:11.521025+00:00 | 2022-08-09T23:01:12.961887+00:00 | 1,280 | false | 1. \u628Acur.next\u5B58\u5230nextnode\u4E2D\uFF0C\u9632\u6B62\u65AD\u5F00\u540E\u627E\u4E0D\u5230\nStore cur.next in nextnode, because we will disconnect the cur->nextnode for the reverse\n\n2. \u8BA9cur\u6307\u5411prev, \u5373 cur.next = prev\nLet cur -> prev for reversing, which is cur.next = prev\n\n3. prev\u548Ccur... | 17 | 0 | ['Two Pointers', 'Python', 'Python3'] | 1 |
reverse-linked-list | CPP Recursive Solution explained | cpp-recursive-solution-explained-by-ujjw-a4wn | The base case for recursion is if list is empty i.e. head points to null or head-> next is null i.e. single element in the list, then the reverse of single elem | ujjw4l | NORMAL | 2021-07-25T15:00:47.136095+00:00 | 2021-07-25T15:00:47.136136+00:00 | 1,257 | false | The base case for recursion is if list is empty i.e. head points to null or head-> next is null i.e. single element in the list, then the reverse of single element is that element itself so we return head itself.\n\nGenerally, in recursion we break the problem into 1 and (n-1) parts where we handle 1 part and let recur... | 17 | 0 | ['Recursion', 'C', 'C++'] | 4 |
reverse-linked-list | Java 2 solutons : In place operation(beats 100%) and Create a new linked list(beats 100%) | java-2-solutons-in-place-operationbeats-2ktvp | Please upvote if it helps,it\'s important for me\uD83D\uDE0A.\n\nHere are two methods :\n1\u3001In place operations(We should master it)\n\n\npublic ListNode re | Sarah_Lene | NORMAL | 2022-03-20T06:00:51.502751+00:00 | 2022-03-20T07:36:42.787914+00:00 | 776 | false | ***Please upvote if it helps,it\'s important for me\uD83D\uDE0A.***\n\nHere are two methods :\n**1\u3001In place operations(We should master it)**\n\n```\npublic ListNode reverseList(ListNode head) {\n ... | 16 | 0 | ['Java'] | 2 |
reverse-linked-list | Easiest way to reverse Linked List explained with Images | easiest-way-to-reverse-linked-list-expla-tz7j | // Hi Devs if you like my post and it helps you please do vote so that it reaches more Devs\n\n\n// In this approach we uses a three pointers \n// p --> previou | Code_Y | NORMAL | 2022-08-31T16:48:40.362788+00:00 | 2022-08-31T16:48:40.362834+00:00 | 2,574 | false | // **Hi Devs if you like my post and it helps you please do vote so that it reaches more Devs**\n\n\n// In this approach we uses a three pointers \n// p --> previous , c --> current , n --> next\n// in every itration we reverse link between p and c , Then move pointers .\n\n:\n# self.val = x\n# self.next = None\n\nclass Solution:\n | huayra | NORMAL | 2019-03-09T02:28:57.862551+00:00 | 2019-03-09T02:28:57.862592+00:00 | 2,405 | false | ```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n\tdef reverseList_i(self, head: ListNode) -> ListNode: # iterative\n\t# O(n) Time / O(1) Space\n\t\tprev = None\n\t\tcur = head\n\t\twhile cur:\n\t\t\ttmp_n... | 15 | 0 | ['Recursion', 'Iterator', 'Python'] | 1 |
reverse-linked-list | Java solution -- recursion and iteration methods | java-solution-recursion-and-iteration-me-58xw | // Recursion: \n\n public ListNode reverseList(ListNode head) {\n return helper(null, head);\n }\n \n ListNode helper(ListNode reversed, List | peng4 | NORMAL | 2015-09-11T21:02:00+00:00 | 2018-09-08T21:01:57.497294+00:00 | 3,225 | false | // Recursion: \n\n public ListNode reverseList(ListNode head) {\n return helper(null, head);\n }\n \n ListNode helper(ListNode reversed, ListNode remaining) {\n if(remaining==null) return reversed;\n ListNode tmp = remaining.next;\n remaining.next = reversed;\n \n r... | 15 | 1 | [] | 2 |
reverse-linked-list | 0ms Simple Java Solution | 0ms-simple-java-solution-by-jguo11-yy39 | public ListNode reverseList(ListNode head) {\n ListNode prev = null;\n while(head != null){\n ListNode next = head.next;\n h | jguo11 | NORMAL | 2016-03-20T17:20:50+00:00 | 2016-03-20T17:20:50+00:00 | 2,277 | false | public ListNode reverseList(ListNode head) {\n ListNode prev = null;\n while(head != null){\n ListNode next = head.next;\n head.next = prev;\n prev = head;\n head = next;\n }\n return prev;\n } | 15 | 0 | ['Java'] | 2 |
reverse-linked-list | Python Recursion Implemention | python-recursion-implemention-by-francis-m5ne | Python Recursion Implemention\n\npython\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# | francisgee | NORMAL | 2017-11-14T03:46:58.990000+00:00 | 2017-11-14T03:46:58.990000+00:00 | 4,371 | false | Python Recursion Implemention\n\n```python\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def reverseList(self, head):\n """\n :type head: ListNode\n :rtype: ListNode\n """\n ... | 15 | 1 | [] | 0 |
reverse-linked-list | [Python Explained Recursive Iterative] | python-explained-recursive-iterative-by-hrik6 | \n\n\nRecursive:\n\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n if not head or not head.next: | Coss_True | NORMAL | 2022-09-15T08:24:06.550725+00:00 | 2022-09-15T10:18:55.571010+00:00 | 1,219 | false | \n\n\nRecursive:\n```\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n if not head or not head.next: # nothing to reverse\n return head... | 14 | 0 | ['Linked List', 'Recursion', 'Python'] | 2 |
reverse-linked-list | One line of code to remember the approach | one-line-of-code-to-remember-the-approac-kqu7 | This problem can be a part of a bigger problem. One can get confused even after solving it previously. \nYou have to remember that we have to manage three upda | jenishah | NORMAL | 2020-03-22T13:46:47.366509+00:00 | 2020-03-22T13:46:47.366540+00:00 | 2,977 | false | This problem can be a part of a bigger problem. One can get confused even after solving it previously. \nYou have to remember that we have to manage three updates , and all updates can be done in one line.\n```\nclass Solution:\n def reverseList(self, head: ListNode) -> ListNode:\n first = head\n if (... | 14 | 2 | ['Python', 'Python3'] | 3 |
reverse-linked-list | Java iterative and recursive solutions, both 0ms and 100% faster | java-iterative-and-recursive-solutions-b-sqd8 | Iteratively:\n\npublic ListNode reverseList(ListNode head) {\n ListNode prev = null;\n ListNode node = head;\n\n while (node != null) {\n ListNo | falmp | NORMAL | 2020-02-11T22:00:54.387948+00:00 | 2020-02-11T22:03:19.379745+00:00 | 1,907 | false | **Iteratively:**\n```\npublic ListNode reverseList(ListNode head) {\n ListNode prev = null;\n ListNode node = head;\n\n while (node != null) {\n ListNode aux = node.next;\n node.next = prev;\n \n prev = node;\n node = aux;\n }\n \n return prev;\n}\n```\n\n**Recursive... | 14 | 0 | ['Recursion', 'Iterator', 'Java'] | 2 |
reverse-linked-list | C++ solution .. very easy.. | c-solution-very-easy-by-homerhickam-60k8 | /**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), | homerhickam | NORMAL | 2015-06-13T20:38:37+00:00 | 2015-06-13T20:38:37+00:00 | 3,705 | false | /**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode(int x) : val(x), next(NULL) {}\n * };\n */\n class Solution {\n public:\n ListNode* reverseList(ListNode* head) {\n ListNode *temp = NULL , *... | 14 | 0 | [] | 2 |
reverse-linked-list | Python | Iterative | Really, really, REALLY simple solution! | python-iterative-really-really-really-si-96ne | The approach is the following: we need to point current node\'s next to the last node we saw, update the last node to be this current node, and move to the next | hemersontacon | NORMAL | 2021-11-11T11:06:32.602631+00:00 | 2021-11-11T11:06:32.602813+00:00 | 812 | false | The approach is the following: we need to point current node\'s next to the last node we saw, update the last node to be this current node, and move to the next node (which is the current node\'s next before any changes). In Python we can do these 3 operations at the same time with the help of tuple (un)packing sintax ... | 13 | 0 | ['Linked List', 'Iterator', 'Python'] | 2 |
reverse-linked-list | Javascript - recursion | javascript-recursion-by-achandel-6guk | \n// time complexity - O (n)\n// space complexity - O (n)\nvar reverseList = function(head) {\n const helper = (current, prev) => {\n if(current === n | achandel | NORMAL | 2020-03-22T21:02:47.041101+00:00 | 2020-03-22T21:02:56.003348+00:00 | 1,910 | false | ```\n// time complexity - O (n)\n// space complexity - O (n)\nvar reverseList = function(head) {\n const helper = (current, prev) => {\n if(current === null) return prev;\n\t\t// next node\n let next = current.next;\n\t\t// append previous nodes in current\n current.next = prev;\n return ... | 13 | 0 | ['Recursion', 'JavaScript'] | 0 |
reverse-linked-list | golang | golang-by-zz12345-nzac | \nfunc reverseList(head *ListNode) *ListNode {\n\tvar prev *ListNode\n\tcur := head\n\tfor cur != nil {\n\t\tprev, cur, cur.Next = cur, cur.Next, prev\n\t}\n\n\ | zz12345 | NORMAL | 2019-12-25T07:58:23.021191+00:00 | 2019-12-25T07:58:23.021229+00:00 | 688 | false | ```\nfunc reverseList(head *ListNode) *ListNode {\n\tvar prev *ListNode\n\tcur := head\n\tfor cur != nil {\n\t\tprev, cur, cur.Next = cur, cur.Next, prev\n\t}\n\n\treturn prev\n}\n``` | 13 | 0 | [] | 5 |
reverse-linked-list | Python solutions | python-solutions-by-amchoukir-p1kz | Iterative\n\npython\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n | amchoukir | NORMAL | 2019-09-14T14:40:23.770867+00:00 | 2019-09-14T14:57:38.645665+00:00 | 2,582 | false | # Iterative\n\n```python\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def reverseList(self, head: ListNode) -> ListNode:\n prev = None\n node = head\n while node:\n next ... | 13 | 0 | ['Python', 'Python3'] | 0 |
reverse-linked-list | 66ms Python recursive 5 lines | 66ms-python-recursive-5-lines-by-nappfly-upgb | \n def reverseList(self, head, last = None):\n if not head:\n return last\n next = head.next\n head.next = last\n retu | nappflying | NORMAL | 2015-05-08T15:58:30+00:00 | 2015-05-08T15:58:30+00:00 | 2,209 | false | \n def reverseList(self, head, last = None):\n if not head:\n return last\n next = head.next\n head.next = last\n return self.reverseList(next, head) | 13 | 0 | [] | 1 |
reverse-linked-list | Clear iterative Python solution | clear-iterative-python-solution-by-edoua-tn1k | class Solution(object):\n def reverseList(self, head):\n \n if not head: return head\n \n p, q = head, head.n | edouardfouche | NORMAL | 2016-02-05T18:12:16+00:00 | 2016-02-05T18:12:16+00:00 | 3,664 | false | class Solution(object):\n def reverseList(self, head):\n \n if not head: return head\n \n p, q = head, head.next\n p.next = None\n \n while q:\n tmp, q.next = q.next, p\n p, q = q, tmp\n \n ... | 13 | 2 | ['Iterator', 'Python'] | 0 |
reverse-linked-list | ITERATIVE + RECURSIVE 🔥🔥 APPROACH || Explanation with images || Easy to understand || Beats 100% | iterative-recursive-approach-explanation-bef4 | Intuition\nReverse Linked List Problem can be solved both iteratively and recursively.\n\nIdea is to reverse all the connections and return the last node as new | dcodeDV | NORMAL | 2024-03-21T18:46:41.109625+00:00 | 2024-03-21T18:54:52.501499+00:00 | 278 | false | # Intuition\nReverse Linked List Problem can be solved both iteratively and recursively.\n\nIdea is to reverse all the connections and return the last node as new head.\n\n- **Iterative Intuition**\n1. For each node `N` we want `N` points to `N-1` and `N+1` points to `N`.\n2. So it is clear from above point that we wil... | 12 | 0 | ['Linked List', 'Recursion', 'C++'] | 4 |
reverse-linked-list | 💯🔥 C++ | Java || Python || JavaScript 💯🔥 | c-java-python-javascript-by-ganya9970-bkcr | \uD83D\uDCAF\uD83D\uDD25 C++ | Java || Python || JavaScript \uD83D\uDCAF\uD83D\uDD25\n\nRead Whole article : https://www.nileshblog.tech/reverse-linked-list/\n\ | ganya9970 | NORMAL | 2023-09-11T06:16:13.555422+00:00 | 2023-09-11T06:16:13.555441+00:00 | 2,787 | false | \uD83D\uDCAF\uD83D\uDD25 C++ | Java || Python || JavaScript \uD83D\uDCAF\uD83D\uDD25\n\nRead Whole article : https://www.nileshblog.tech/reverse-linked-list/\n\nExplanation with Human Hand Eg.\n\nPython :\nJava:\nc++:\nJavaScript:\n\nTime Complexity :\nO(n)\n\nRead Whole article : https://www.nileshblog.tech/reverse-li... | 12 | 0 | ['C', 'Python', 'Java', 'JavaScript'] | 1 |
reverse-linked-list | SIMPLE JAVASCRIPT 98% BEATS || EASY EXPLANATION | simple-javascript-98-beats-easy-explanat-ph89 | \n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. The reverseList function takes a head parameter representing the head of the | ikboljonme | NORMAL | 2023-03-28T23:52:13.159277+00:00 | 2023-03-28T23:52:13.159306+00:00 | 3,237 | false | \n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. The reverseList function takes a head parameter representing the head of the linked list... | 12 | 0 | ['JavaScript'] | 3 |
reverse-linked-list | Golang Simple Recursive with Explanation | golang-simple-recursive-with-explanation-4s5k | Solution\n Describe your approach to solving the problem. \nThis is the explanation for this recursive solution. For simplicity, we will use an input head that | jaydenteoh | NORMAL | 2022-11-25T15:41:49.274211+00:00 | 2022-11-25T15:47:48.393641+00:00 | 1,372 | false | # Solution\n<!-- Describe your approach to solving the problem. -->\nThis is the explanation for this recursive solution. For simplicity, we will use an input head that points to 1 -> 2 -> 3.\n\nI\'ll run through the recursive solution in chronological layers.\n\n### Outer Layer:\nInput 1 (current) = 1 -> 2 -> 3 -> nil... | 12 | 0 | ['Recursion', 'Go'] | 0 |
reverse-linked-list | C# accepted, recursive, with simple explanations | c-accepted-recursive-with-simple-explana-2nmu | Given: \n1->2->3->4\n\nReverse the list after first node: \n1->(2->3->4)\n\nBecame: \n4->3->2, \n1->2\n\nNow we need to let: \n2->1, 1->null\n\nand get result: | rain4 | NORMAL | 2015-10-01T21:14:02+00:00 | 2015-10-01T21:14:02+00:00 | 1,058 | false | Given: \n1->2->3->4\n\nReverse the list after first node: \n1->(2->3->4)\n\nBecame: \n4->3->2, \n1->2\n\nNow we need to let: \n2->1, 1->null\n\nand get result: \n4->3->2->1->null\n\n public ListNode ReverseList(ListNode head)\n {\n if (head == null || head.next == null)\n {\n ... | 12 | 1 | ['Recursion'] | 2 |
reverse-linked-list | TWO APPROACH || ITERATIVE & RECURSIVE || EASY JAVA SOLUTION || BEATS 100% | two-approach-iterative-recursive-easy-ja-2o1f | Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | 202151174 | NORMAL | 2023-07-15T11:10:18.155797+00:00 | 2023-07-15T11:10:18.155814+00:00 | 1,030 | false | # Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode... | 11 | 0 | ['Linked List', 'Recursion', 'Java'] | 0 |
reverse-linked-list | Easy Explained Solution - Beats 100% | easy-explained-solution-beats-100-by-dee-ta0x | Please Upvote my solution, if you find it helpful ;)\n\n# Intuition\nThink of a linked list as a chain of nodes where each node points to the next node in the c | deepankyadav | NORMAL | 2023-06-30T17:34:38.412258+00:00 | 2023-06-30T17:34:38.412281+00:00 | 1,988 | false | ## ***Please Upvote my solution, if you find it helpful ;)***\n\n# Intuition\nThink of a linked list as a chain of nodes where each node points to the next node in the chain. Reversing a linked list means changing the direction of the chain, making the last node the new head, and the previous head the new tail.\n# Appr... | 11 | 0 | ['Linked List', 'Two Pointers', 'Python', 'C++', 'Java'] | 1 |
reverse-linked-list | C++/Java/Python/JavaScript|| ✅🚀Space: O(1) Simple Solution || ✔️🔥Easy To Understand | cjavapythonjavascript-space-o1-simple-so-1xzs | Intuition\nTake the head of a singly-linked list as input and reverses the list.\n\n# Approach\n\n1. Check if the head is NULL. If it is, it means the list is e | devanshupatel | NORMAL | 2023-05-20T18:40:22.832053+00:00 | 2023-05-20T18:40:22.832083+00:00 | 5,775 | false | # Intuition\nTake the head of a singly-linked list as input and reverses the list.\n\n# Approach\n\n1. Check if the head is NULL. If it is, it means the list is empty, so we return the head as it is.\n\n2. Create two pointers, "current" and "previous," and initialize "current" with the head of the list and "previous" w... | 11 | 0 | ['Linked List', 'Python', 'C++', 'Java', 'JavaScript'] | 1 |
reverse-linked-list | [Python] EASY-understanding, Clear and Intuitive with illustration☝️🖼🖍 for beginners | python-easy-understanding-clear-and-intu-dj53 | Given a linked list: \n\n\t 0\uFE0F\u20E3 \u279D 1\uFE0F\u20E3 \u279D 2\uFE0F\u20E3 \u279D 3\uFE0F\u20E3 \u279D 4\uFE0F\u20E3\n\t \u261D\uFE0E\n\thead\n\n\nFrom | ziaiz-zythoniz | NORMAL | 2022-05-13T09:27:31.540748+00:00 | 2022-05-14T03:48:19.933404+00:00 | 547 | false | Given a linked list: \n```\n\t 0\uFE0F\u20E3 \u279D 1\uFE0F\u20E3 \u279D 2\uFE0F\u20E3 \u279D 3\uFE0F\u20E3 \u279D 4\uFE0F\u20E3\n\t \u261D\uFE0E\n\thead\n```\n\nFrom a beginner\'s point of view, what we need to do is:\n\n_________________________________________________________\n\n**Step 0. Initialize the new linked l... | 11 | 0 | ['Linked List', 'Two Pointers', 'Iterator', 'Python'] | 3 |
reverse-linked-list | Rust move-only solution | rust-move-only-solution-by-brainplot-uc26 | rust\nimpl Solution {\n pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let mut prev: Option<Box<ListNode>> = None;\n | brainplot | NORMAL | 2020-06-06T04:34:59.660027+00:00 | 2020-06-06T04:35:37.309496+00:00 | 867 | false | ```rust\nimpl Solution {\n pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {\n let mut prev: Option<Box<ListNode>> = None;\n let mut curr = head;\n \n while let Some(mut boxed_node) = curr {\n let mut next = boxed_node.next.take();\n boxed_n... | 11 | 0 | ['Rust'] | 2 |
reverse-linked-list | Python 3-liner to memorize for interviews (with mnemonic) | python-3-liner-to-memorize-for-interview-r2dk | I had an interview where I solved a LeetCode-medium problem in 15 minutes, but took 10-15 minutes to reverse a linked list in another problem because I kept stu | zemer | NORMAL | 2018-10-23T21:20:16.883214+00:00 | 2018-10-25T21:55:30.328134+00:00 | 1,209 | false | I had an interview where I solved a LeetCode-medium problem in 15 minutes, but took 10-15 minutes to reverse a linked list in another problem because I kept stumbling over stupid trivial things under pressure. I didn\'t get the job because the interviewer assumed I\'d seen the hard problem before but "couldn\'t even do... | 11 | 0 | [] | 2 |
reverse-linked-list | Beats 100% || Best Solution Recursion🔥|| HandWritten Notes++ || Java, C++, Python | beats-100-best-solution-recursion-handwr-cq6r | Intuition & Approach
ComplexityCode | VIBHU_DIXIT | NORMAL | 2025-03-13T03:28:14.959874+00:00 | 2025-03-13T03:28:14.959874+00:00 | 603 | false | # Intuition & Approach


# Complexity
 Solution | python-9368-faster-iterative-on-solution-xvh0 | \nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n if head==None or head.next==None: return head\n pr | pulkit_uppal | NORMAL | 2022-11-26T14:35:55.342343+00:00 | 2022-11-26T14:35:55.342366+00:00 | 1,769 | false | ```\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n if head==None or head.next==None: return head\n prev,curr,temp=head,head.next,head.next.next\n prev.next=None\n while temp:\n curr.next=prev\n prev=curr\n curr=... | 10 | 0 | ['Linked List', 'Iterator', 'Python', 'Python3'] | 0 |
reverse-linked-list | Java 0ms 100% Faster | Recursion | Easy | Intution Explained | java-0ms-100-faster-recursion-easy-intut-zz7g | Intution : We have to manipulate (reverse) the pointer of the linked list, in order to reverse the entire linked list.\nRecursive Intution : We\'ll reverse one | iamharshpathak | NORMAL | 2022-05-11T05:12:07.870756+00:00 | 2022-05-11T05:12:44.511675+00:00 | 763 | false | ***Intution : We have to manipulate (reverse) the pointer of the linked list, in order to reverse the entire linked list.\nRecursive Intution : We\'ll reverse one pointer, others will be done by the function itself (recursive leap of faith ) !***\n\n```\nclass Solution {\n public ListNode reverseList(ListNode head) ... | 10 | 0 | ['Recursion', 'Java'] | 0 |
reverse-linked-list | C++ Simplest Iterative Approach | c-simplest-iterative-approach-by-ayushma-0xgq | \nclass Solution {\npublic:\n ListNode reverseList(ListNode head) {\n \n ListNode previous = NULL;\n ListNode current = head;\n L | AyushMaheshwari | NORMAL | 2022-01-05T15:57:47.842751+00:00 | 2022-01-05T15:57:47.842793+00:00 | 556 | false | \nclass Solution {\npublic:\n ListNode* reverseList(ListNode* head) {\n \n ListNode* previous = NULL;\n ListNode* current = head;\n ListNode* next;\n while(current != NULL)\n {\n next = current -> next;\n current -> next = previous;\n \n ... | 10 | 0 | ['Linked List', 'C', 'Iterator'] | 0 |
reverse-linked-list | C# | c-by-rajeevarakkal-jlbe | Runtime: 92 ms, faster than 72.27% of C# online submissions for Reverse Linked List.\nMemory Usage: 25.2 MB, less than 40.36% of C# online submissions for Rever | rajeevarakkal | NORMAL | 2021-06-29T15:16:27.111916+00:00 | 2021-06-29T15:16:27.111966+00:00 | 4,450 | false | Runtime: 92 ms, faster than 72.27% of C# online submissions for Reverse Linked List.\nMemory Usage: 25.2 MB, less than 40.36% of C# online submissions for Reverse Linked List.\n\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * public int val;\n * public ListNode next;\n * pub... | 10 | 0 | [] | 1 |
reverse-linked-list | PYTHON CODE WITH FULL DETAILED EXPLANATIONS | python-code-with-full-detailed-explanati-584e | The comments are already added regarding the logic although its pretty staright forward and simple\n\n # SO bacially we will take 3 pointers one is \n | shubhamverma2604 | NORMAL | 2021-03-25T15:58:38.202189+00:00 | 2021-03-25T15:58:38.202231+00:00 | 1,020 | false | The comments are already added regarding the logic although its pretty staright forward and simple\n\n # SO bacially we will take 3 pointers one is \n #curr = head\n #prev\n #next i.e. curr.next coz if we will directly point our curr.next to prev then we loose connection with curr.next\n ... | 10 | 2 | ['Linked List', 'Python', 'Python3'] | 0 |
reverse-linked-list | Go | go-by-dynasty919-fwk3 | \nfunc reverseList(head *ListNode) *ListNode {\n var front *ListNode\n mid, end := head, head\n for mid != nil {\n end = mid.Next\n mid.N | dynasty919 | NORMAL | 2020-03-12T06:39:20.079773+00:00 | 2020-03-12T06:39:20.079821+00:00 | 1,034 | false | ```\nfunc reverseList(head *ListNode) *ListNode {\n var front *ListNode\n mid, end := head, head\n for mid != nil {\n end = mid.Next\n mid.Next = front\n front, mid = mid, end\n }\n return front\n}\n``` | 10 | 0 | [] | 2 |
reverse-linked-list | JavaScript - Iterative & Recursive | javascript-iterative-recursive-by-grs-p47k | Iterative\n\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar reverseList = function(head) {\n let prev = null;\n while (head) {\n c | grs | NORMAL | 2019-07-20T09:50:43.458359+00:00 | 2019-07-20T09:50:43.458396+00:00 | 1,110 | false | **Iterative**\n```\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar reverseList = function(head) {\n let prev = null;\n while (head) {\n const next = head.next;\n const curr = head;\n curr.next = prev;\n head = next;\n prev = curr;\n }\n \n return prev;\... | 10 | 0 | [] | 0 |
reverse-linked-list | Share my Accepted Java solution - iteratively and recursively: | share-my-accepted-java-solution-iterativ-w879 | Iteratively:\n\n public ListNode reverseList(ListNode head) {\n if(head == null || head.next == null)\n return head;\n L | sammy89 | NORMAL | 2015-07-25T21:39:09+00:00 | 2015-07-25T21:39:09+00:00 | 1,648 | false | **Iteratively:**\n\n public ListNode reverseList(ListNode head) {\n if(head == null || head.next == null)\n return head;\n ListNode pre = null;\n ListNode curr = head;\n while(curr != null){\n ListNode next = curr.next;\n curr.n... | 10 | 0 | ['Java'] | 3 |
reverse-linked-list | Ac solution code | ac-solution-code-by-cheng_zhang-lx9n | Solution1. Iterative Solution\n\n public ListNode reverseList(ListNode head) {\n \tListNode prev = null, curr = head;\n \twhile (curr != null) { \n | cheng_zhang | NORMAL | 2016-01-11T05:28:21+00:00 | 2016-01-11T05:28:21+00:00 | 877 | false | **Solution1. Iterative Solution**\n\n public ListNode reverseList(ListNode head) {\n \tListNode prev = null, curr = head;\n \twhile (curr != null) { \n \t ListNode next = curr.next;// Save current's next \n \t\tcurr.next = prev;// Point current.next to prev\n \t\tprev = curr;// Set the current node... | 10 | 0 | [] | 1 |
reverse-linked-list | Easy✅JAVA&C++&JAVASCRIPT|| 🗓️ Daily LeetCoding Challenge Day 4✅🔥 | easyjavacjavascript-daily-leetcoding-cha-b19x | I hope a nice day for u!!\njava []\nclass Solution {\n public ListNode reverseList(ListNode head) {\n return reverse(head);\n }\n private ListNo | DoaaOsamaK | NORMAL | 2024-03-21T07:16:32.702205+00:00 | 2024-03-21T07:19:22.928600+00:00 | 895 | false | I hope a nice day for u!!\n```java []\nclass Solution {\n public ListNode reverseList(ListNode head) {\n return reverse(head);\n }\n private ListNode reverse(ListNode head){\n ListNode curr = head, prev = null;\n while(curr != null){\n ListNode nextNode = curr.next;\n c... | 9 | 0 | ['C++', 'Java', 'JavaScript'] | 1 |
reverse-linked-list | 🔥Simple C++ Solution || using 3 pointer || iterative 🔥 | simple-c-solution-using-3-pointer-iterat-xkr9 | \n Describe your approach to solving the problem. \n\n\n Add your time complexity here, e.g. O(n) \n\n\n Add your space complexity here, e.g. O(n) \n\n# Code\n\ | rishav_raj_16 | NORMAL | 2023-02-12T14:26:42.658375+00:00 | 2024-06-10T11:29:41.053462+00:00 | 932 | false | \n<!-- Describe your approach to solving the problem. -->\n\n\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : ... | 9 | 0 | ['Linked List', 'C'] | 0 |
reverse-linked-list | Python [Iterative: Beats 99% || Recursive: Beats 87%] with full working explanation | python-iterative-beats-99-recursive-beat-0kfs | Iterative\n\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: # Time: O(n) and Space: O(1)\n prev, cur = None | DanishKhanbx | NORMAL | 2022-08-12T11:12:46.514285+00:00 | 2022-08-12T11:12:46.514379+00:00 | 1,321 | false | # Iterative\n```\nclass Solution:\n def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: # Time: O(n) and Space: O(1)\n prev, cur = None, head\n while cur: # let cur 3 \n temp = cur.next # nxt = 4\n cur.next = prev # 3 -> 2\n p... | 9 | 0 | ['Recursion', 'Python', 'Python3'] | 1 |
reverse-linked-list | Python3 3 Solutions iterative, recursive, and stack. | python3-3-solutions-iterative-recursive-l8vob | The three solutions contains stack, recursive, iterative solution\nyou can clearly see the best runtime, I\'ve got is come with stack, but we can do better, wit | arshergon | NORMAL | 2022-05-21T14:35:44.846981+00:00 | 2022-05-21T14:35:44.847011+00:00 | 778 | false | The three solutions contains stack, recursive, iterative solution\nyou can clearly see the best runtime, I\'ve got is come with stack, but we can do better, with O(1) memory, leetcode servers result comes different everytime you hit submit.\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init... | 9 | 0 | ['Stack', 'Python', 'Python3'] | 0 |
minimum-number-of-taps-to-open-to-water-a-garden | [Java] A general greedy solution to process similar problems | java-a-general-greedy-solution-to-proces-39dp | This problem is similiar to Jump game II and Video Stiching. Just summary a general idea to process this kind of problems for the conveninece of review in the f | bluecamel | NORMAL | 2020-02-12T08:57:13.607399+00:00 | 2020-02-21T07:13:02.895381+00:00 | 29,528 | false | This problem is similiar to **Jump game II** and **Video Stiching**. Just summary a general idea to process this kind of problems for the conveninece of review in the future. (Welcome supplement other similar ones, thanks in advance).\n\nFirst we need ensure that the array has been sorted by start time. Then say in eac... | 499 | 4 | [] | 47 |
minimum-number-of-taps-to-open-to-water-a-garden | [Java/C++/Python] Similar to LC1024 | javacpython-similar-to-lc1024-by-lee215-b59a | Intuition\nExample 2 did confuse me.\nWe actually need to water the whole segment, instead of n + 1 point.\nThe taps with value 0 can water nothing.\n\n\n# Solu | lee215 | NORMAL | 2020-01-19T04:01:06.771901+00:00 | 2020-01-23T12:30:11.300138+00:00 | 42,224 | false | # Intuition\nExample 2 did confuse me.\nWe actually need to water the whole segment, instead of `n + 1` point.\nThe taps with value `0` can water nothing.\n<br>\n\n# Solution 1: Brute Force DP\n`dp[i]` is the minimum number of taps to water `[0, i]`.\nInitialize `dp[i]` with max = `n + 2`\n`dp[0] = [0]` as we need no t... | 262 | 17 | [] | 39 |
minimum-number-of-taps-to-open-to-water-a-garden | [Python] Jump Game II | python-jump-game-ii-by-kytabyte-pd5t | \nWe build a list max_range to store the max range it can be watered from each index. \n\nThen it becomes Jump Game II, where we want to find the minimum steps | kytabyte | NORMAL | 2020-01-19T04:10:25.145866+00:00 | 2020-01-23T03:21:51.722791+00:00 | 13,122 | false | \nWe build a list `max_range` to store the max range it can be watered from each index. \n\nThen it becomes [Jump Game II](https://leetcode.com/problems/jump-game-ii/), where we want to find the minimum steps to jump from `0` to `n`.\n\nThe only difference is Jump Game II guarantees we can jump to the last index but t... | 203 | 0 | [] | 23 |
minimum-number-of-taps-to-open-to-water-a-garden | DP pattern to solve 3 similar problems | dp-pattern-to-solve-3-similar-problems-b-dh88 | We can use the same DP pattern to solve the following 3 problems.\n\n 1326. Minimum Number of Taps to Open to Water a Garden\n\n public int minTaps(int[] range | chenzuojing | NORMAL | 2020-06-30T06:38:59.514292+00:00 | 2021-08-03T21:15:09.958101+00:00 | 10,488 | false | We can use the same DP pattern to solve the following 3 problems.\n\n* 1326. Minimum Number of Taps to Open to Water a Garden\n```\n public int minTaps(int[] ranges) {\n\t\tint len = ranges.length;\n\t\tint[] dp = new int[len]; \n\t\tArrays.fill(dp, len + 1); \n\t\tdp[0] = 0;\n\n\t\tfor (int i = 0; i < len; i++) {\n\t... | 145 | 3 | [] | 9 |
minimum-number-of-taps-to-open-to-water-a-garden | ✅ 99.5% Greedy with Dynamic + DP | 995-greedy-with-dynamic-dp-by-vanamsen-mygc | Interview Guide - Minimum Number of Taps to Open to Water a Garden\n\n## Problem Understanding\n\n### Description\nAt its core, this problem is a fascinating bl | vanAmsen | NORMAL | 2023-08-31T00:14:11.946782+00:00 | 2023-08-31T01:45:04.612085+00:00 | 15,370 | false | # Interview Guide - Minimum Number of Taps to Open to Water a Garden\n\n## Problem Understanding\n\n### Description\nAt its core, this problem is a fascinating blend of interval merging and greedy optimization. You are provided with a one-dimensional garden and the ability to water certain intervals of it by opening ta... | 108 | 8 | ['Dynamic Programming', 'Greedy', 'PHP', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript', 'C#'] | 7 |
minimum-number-of-taps-to-open-to-water-a-garden | [C++] O(n) no sort, similar to Jump Game II | c-on-no-sort-similar-to-jump-game-ii-by-80hg3 | The question can be converted into the form of Jump Game II.\n\n1. The range each tap covers is: max(0, i-ranges[i]) (say l) to min(n, i+ranges[i]) (say r). Thi | sarthaksehgal | NORMAL | 2020-01-21T04:37:24.667459+00:00 | 2020-11-10T09:16:18.537805+00:00 | 9,754 | false | The question can be converted into the form of [Jump Game II](https://leetcode.com/problems/jump-game-ii/).\n\n1. The range each tap covers is: `max(0, i-ranges[i])` (say `l`) to `min(n, i+ranges[i])` (say `r`). Think of this range as a jump starting from the index `max(0,i-ranges[i])` with maximum reach till `min(n, i... | 91 | 3 | [] | 9 |
minimum-number-of-taps-to-open-to-water-a-garden | ✅ Simple 7 line solution w/ explanation ⬆️ BEST🧠 | simple-7-line-solution-w-explanation-bes-6c8q | small request - please give an upvote if it helps \uD83D\uDC31\u267B\uFE0F\uD83D\uDC31\n\n# Code\nCPP []\nclass Solution {\nint minTaps(int n, vector<int>& rang | trishitchar | NORMAL | 2023-08-31T08:09:06.719482+00:00 | 2023-08-31T08:48:59.913034+00:00 | 2,753 | false | # small request - please give an upvote if it helps \uD83D\uDC31\u267B\uFE0F\uD83D\uDC31\n\n# Code\n```CPP []\nclass Solution {\nint minTaps(int n, vector<int>& ranges) {\n int min=0, max=0, count=0; // Initialize variables to keep track of the minimum and maximum reach, and the number of taps used.\n wh... | 54 | 1 | ['Greedy', 'C', 'C++', 'Java', 'Python3'] | 7 |
minimum-number-of-taps-to-open-to-water-a-garden | C++ (3 explained/commented approaches) | c-3-explainedcommented-approaches-by-maz-ze32 | \n//Approach-1 (Brute Force)\nclass Solution {\npublic: \n int minTaps(int n, vector<int>& ranges) {\n int min = 0;\n int max = 0;\n | mazhar_mik | NORMAL | 2021-07-17T15:46:53.929227+00:00 | 2021-07-17T15:46:53.929257+00:00 | 3,215 | false | ```\n//Approach-1 (Brute Force)\nclass Solution {\npublic: \n int minTaps(int n, vector<int>& ranges) {\n int min = 0;\n int max = 0;\n int count = 0;\n while(max < n) {\n \n //Choose the tap with maximum range it can reach to right\n //For a given ... | 42 | 0 | [] | 4 |
minimum-number-of-taps-to-open-to-water-a-garden | [Java/Python 3] Sort and greedy, similar to 1024 video stitching, w/ brief explanation and analysis. | javapython-3-sort-and-greedy-similar-to-ysxe7 | The ranges can cover intervals: [i - ranges[i], i + ranges[i]]; Sort them by their low bounds;\n2. start starting from 0, if it is not less than the low bound o | rock | NORMAL | 2020-01-19T04:02:13.760993+00:00 | 2020-01-20T04:20:55.961347+00:00 | 5,677 | false | 1. The `ranges` can cover intervals: `[i - ranges[i], i + ranges[i]]`; Sort them by their low bounds;\n2. `start` starting from `0`, if it is not less than the low bound of current interval, update `end` to the high bound; move to next interval; \n3. Repeat step 2 till low bound of current interval larger than `start`;... | 41 | 0 | [] | 6 |
minimum-number-of-taps-to-open-to-water-a-garden | Wrong test? | wrong-test-by-nvda-v88p | For this test case, can someone please explain why the answer is 6 instead of 5?\n\n35\n[1,0,4,0,4,1,4,3,1,1,1,2,1,4,0,3,0,3,0,3,0,5,3,0,0,1,2,1,2,4,3,0,1,0,5,2 | nvda | NORMAL | 2020-01-19T04:05:13.873400+00:00 | 2020-01-21T13:48:32.007513+00:00 | 2,673 | false | For this test case, can someone please explain why the answer is 6 instead of 5?\n\n35\n[1,0,4,0,4,1,4,3,1,1,1,2,1,4,0,3,0,3,0,3,0,5,3,0,0,1,2,1,2,4,3,0,1,0,5,2]\n\n\nyou can use the following configuration to get the answer 5\n[1,0,4,0,4,1,4,3,1|1,1,2,1,4,0,3,0,3|0,3,0,5,3,0,0,1,2|1,2,4,3,0,1,0|5,2]\n 1,1,1,1,1,1,1,1,... | 40 | 0 | [] | 11 |
minimum-number-of-taps-to-open-to-water-a-garden | C++ || DP (recursion + memoization) || Day 31 | c-dp-recursion-memoization-day-31-by-chi-vclp | Code\n\nclass Solution{\npublic:\n int N;\n long dp[10008];\n long help(int i, vector<pair<int, int>> &vp)\n {\n if (vp[i].second == N)\n | CHIIKUU | NORMAL | 2023-08-31T04:52:22.272799+00:00 | 2023-08-31T04:52:22.272820+00:00 | 4,910 | false | Code\n```\nclass Solution{\npublic:\n int N;\n long dp[10008];\n long help(int i, vector<pair<int, int>> &vp)\n {\n if (vp[i].second == N)\n return 1;\n if (i == vp.size())\n return INT_MAX;\n if (dp[i] != -1)\n return dp[i];\n long ans = INT_MAX;... | 35 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Recursion', 'Memoization', 'C++'] | 3 |
minimum-number-of-taps-to-open-to-water-a-garden | [Java] Jump game II. O(N) time and O(1) space | java-jump-game-ii-on-time-and-o1-space-b-n0ma | If you have not done Jump Game porblems, try resolving that first: https://leetcode.com/problems/jump-game-ii/\n\nAssuming you already understand the Jump Game | liang54 | NORMAL | 2020-09-01T15:48:08.834299+00:00 | 2020-09-01T15:48:08.834346+00:00 | 2,223 | false | If you have not done Jump Game porblems, try resolving that first: https://leetcode.com/problems/jump-game-ii/\n\nAssuming you already understand the Jump Game II solution, now in this problem, you just need to convert the ranges array to the max point you can get from each index.\n\n```\n public int minTaps(int n, int... | 34 | 0 | [] | 4 |
minimum-number-of-taps-to-open-to-water-a-garden | 【Video】Beat 95% solution with Python, JavaScript, Java and C++ | video-beat-95-solution-with-python-javas-6kwp | Intuition\nThe most important idea to solve this question is to utilize the concept of dynamic programming by transforming the tap ranges into intervals. This a | niits | NORMAL | 2023-08-31T03:42:02.157614+00:00 | 2023-08-31T08:57:03.021029+00:00 | 1,793 | false | # Intuition\nThe most important idea to solve this question is to utilize the concept of dynamic programming by transforming the tap ranges into intervals. This allows you to efficiently determine the coverage of each tap and select the optimal intervals to minimize the number of taps required to water the entire garde... | 33 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 1 |
minimum-number-of-taps-to-open-to-water-a-garden | [Java] O(n) solution | beat 100% | Greedy | java-on-solution-beat-100-greedy-by-adkm-18c9 | Iterate through all the intervals and store the longest position value that can be reached\nEvery time choose to go to the farthest point it can reach\n\nclass | adkmr | NORMAL | 2020-01-19T04:19:53.839827+00:00 | 2020-01-19T04:19:53.839876+00:00 | 5,131 | false | Iterate through all the intervals and store the longest position value that can be reached\nEvery time choose to go to the farthest point it can reach\n```\nclass Solution {\n public int minTaps(int n, int[] ranges) {\n int[] intervals = new int[n];\n Arrays.fill(intervals, -1);\n for (int i = 0... | 32 | 0 | ['Greedy', 'Java'] | 6 |
minimum-number-of-taps-to-open-to-water-a-garden | 【Video】Beat 95% solution with Python, JavaScript, Java and C++ | video-beat-95-solution-with-python-javas-37tq | IntuitionThe most important idea to solve this question is to utilize the concept of dynamic programming by transforming the tap ranges into intervals. This all | niits | NORMAL | 2025-01-14T16:40:45.263317+00:00 | 2025-01-14T17:57:28.449940+00:00 | 648 | false | # Intuition
The most important idea to solve this question is to utilize the concept of dynamic programming by transforming the tap ranges into intervals. This allows you to efficiently determine the coverage of each tap and select the optimal intervals to minimize the number of taps required to water the entire garden... | 28 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
minimum-number-of-taps-to-open-to-water-a-garden | [Python] O(1) memory O(n) time Greedy With Explanation (132ms beats 100%) | python-o1-memory-on-time-greedy-with-exp-gp25 | Constant Space! O(n) Greedy Approuch (AC: 132ms beats 100%)\nThis question is very similar to Jump Game II. \n1. Inplace modify ranges so that each element repr | yanrucheng | NORMAL | 2020-01-19T04:02:20.117675+00:00 | 2020-01-19T06:08:01.585560+00:00 | 2,630 | false | **Constant Space! O(n) Greedy Approuch (AC: 132ms beats 100%)**\nThis question is very similar to [Jump Game II](https://leetcode.com/problems/jump-game-ii/). \n1. Inplace modify `ranges` so that each element represents the furthest index you can reach by taking one jump.\n2. Find the minimal jump you need to reach the... | 28 | 1 | ['Greedy', 'Python'] | 1 |
minimum-number-of-taps-to-open-to-water-a-garden | Python : O(N) | python-on-by-fallenranger-t9s7 | Create jumps array which stores the maximum coverage from a point.\nThen problem is just reduced to reaching last index from 0th index in minimum jumps using ju | fallenranger | NORMAL | 2020-01-19T04:04:19.724338+00:00 | 2020-01-19T05:33:28.127640+00:00 | 3,482 | false | Create jumps array which stores the maximum coverage from a point.\nThen problem is just reduced to reaching last index from 0th index in minimum jumps using jumps array.\n[Jump Array 2](https://leetcode.com/problems/jump-game-ii/)\n\n```\nclass Solution:\n def minTaps(self, n: int, ranges: List[int]) -> int:\n ... | 25 | 0 | ['Python', 'Python3'] | 10 |
minimum-number-of-taps-to-open-to-water-a-garden | Easy solution| Line By Line explanation 🔥| DP and Greedy Approach | Python | Beats 90+% | 🍾🔥 | easy-solution-line-by-line-explanation-d-tad5 | Intuition\nThe problem challenges us to water an entire one-dimensional garden using the fewest number of taps. Each tap has a range that it can water. The crux | Pratikk_Rathod | NORMAL | 2023-08-31T04:07:04.382938+00:00 | 2023-08-31T18:52:02.837682+00:00 | 1,590 | false | # Intuition\n**The problem challenges us to water an entire one-dimensional garden using the fewest number of taps. Each tap has a range that it can water. The crux of our solution is to always choose the tap that allows us to water the farthest point in the garden that hasn\'t been watered yet.**\n<!-- Describe your f... | 23 | 0 | ['Python', 'Python3'] | 7 |
minimum-number-of-taps-to-open-to-water-a-garden | Simple Solution || Beginner Friendly || Easy to Understand 🔥 | simple-solution-beginner-friendly-easy-t-eieb | Approach\n Describe your approach to solving the problem. \n- Create an array maxReach to store the farthest endpoints that can be reached from each starting po | Anirban_Pramanik10 | NORMAL | 2023-08-31T01:37:54.388204+00:00 | 2023-08-31T02:00:33.914631+00:00 | 3,372 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n- Create an array `maxReach` to store the farthest endpoints that can be reached from each starting point.\n- Iterate through the `ranges` array:\n- Calculate starting and ending points for each tap\'s reach.\n- Update `maxReach` at the starting point... | 21 | 3 | ['Array', 'Dynamic Programming', 'Greedy', 'C', 'C++', 'Java', 'Python3'] | 5 |
minimum-number-of-taps-to-open-to-water-a-garden | [Clean C++] Treat it as another interval problem (Like Video Stitching) | clean-c-treat-it-as-another-interval-pro-cknz | Same as : https://leetcode.com/problems/video-stitching/\n\n\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector <vector<i | abhisharma404 | NORMAL | 2020-07-09T06:46:12.197399+00:00 | 2020-07-09T06:47:30.320226+00:00 | 2,538 | false | Same as : https://leetcode.com/problems/video-stitching/\n\n```\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector <vector<int>> intervals;\n for (int i = 0; i < ranges.size(); i++) {\n vector<int> inter{i - ranges[i], i + ranges[i]};\n intervals.push_... | 20 | 3 | ['Greedy', 'Recursion', 'C', 'Sorting', 'C++'] | 0 |
minimum-number-of-taps-to-open-to-water-a-garden | Greedy python O(N log(N)) beats 97% | greedy-python-on-logn-beats-97-by-akshay-uf0c | Convert the ranges into intervals [start, end] and sort them by the start positions\n2. In each iteration find a pipe such that its start is <= the end of the p | akshayagg | NORMAL | 2021-01-21T11:09:33.874250+00:00 | 2021-01-21T11:13:28.862309+00:00 | 1,614 | false | 1. Convert the ranges into intervals [start, end] and sort them by the start positions\n2. In each iteration find a pipe such that its start is <= the end of the prev pipe and has the largest end among all such pipes. \n3. Continue till we find a pipe whose end >= n\n\n`n = 7 ranges=[1,2,1,0,2,1,0,1]`\n`intervals = [(-... | 17 | 0 | ['Greedy', 'Python'] | 1 |
minimum-number-of-taps-to-open-to-water-a-garden | ✅Easy Solution✅Python/C#/C++/Java/C🔥Clean Code🔥 | easy-solutionpythonccjavacclean-code-by-ruk88 | Problem\n\nThis problem involves finding the minimum number of taps that need to be open to water the entire garden. The garden is represented as a one-dimensio | MrAke | NORMAL | 2023-08-31T03:29:03.062100+00:00 | 2023-08-31T03:29:03.062121+00:00 | 1,100 | false | # Problem\n***\nThis problem involves finding the minimum number of taps that need to be open to water the entire garden. The garden is represented as a one-dimensional axis from 0 to n, and each tap can water a specific range around its location. The goal is to determine the minimum number of taps you need to turn on ... | 16 | 2 | ['C', 'Python', 'C++', 'Java', 'Python3', 'C#'] | 1 |
minimum-number-of-taps-to-open-to-water-a-garden | O(n) time complexity greedy implementation in C++ with comments | on-time-complexity-greedy-implementation-l26r | \nclass Solution {\npublic:\n int minTaps(int n, vector<int>& nums) {\n vector<int> maxRight(n+1); //maxRight[Left]=the farest index Left can reach\n | djw612 | NORMAL | 2020-07-15T05:02:25.468267+00:00 | 2020-07-15T05:02:25.468306+00:00 | 1,461 | false | ```\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& nums) {\n vector<int> maxRight(n+1); //maxRight[Left]=the farest index Left can reach\n \n // scan each tap, update the farest index each Left can reach.\n for (int i =0;i<=n;i++){\n int L = max(0,i-nums[i]);\n ... | 16 | 0 | [] | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.