title stringlengths 1 100 | titleSlug stringlengths 3 77 | Java int64 0 1 | Python3 int64 1 1 | content stringlengths 28 44.4k | voteCount int64 0 3.67k | question_content stringlengths 65 5k | question_hints stringclasses 970
values |
|---|---|---|---|---|---|---|---|
✅Beats 100% || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | maximum-subarray | 1 | 1 | # Intuition\nThe Intuition behind the code is to find the maximum sum of a contiguous subarray within the given array `nums`. It does this by scanning through the array and keeping track of the current sum of the subarray. Whenever the current sum becomes greater than the maximum sum encountered so far, it updates the ... | 324 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
90% intuitive Python solution -- Imagine you are walking through a mountain range | maximum-subarray | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n Imagine the array is a list of steps up and down in the mountain. You are traversing the mountain from left to right.\n You are wondering what is the longest way up there is in this mountain.\n\n Keep track of the lowest point... | 1 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
Simple Python Solution | maximum-subarray | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSolve Problem using basic and simple python knowledge\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nKadane\'s algorithm\n\n**Explanation:**\n\n Initialization:\n\n---\n\n\n- arr: The input array for which we want... | 1 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
Kadane's Algo || O(n) time and O(1) space || Easiest Beginner friendly Sol | maximum-subarray | 1 | 1 | **NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Intuition of this Problem:\nWe can solve this problem using **Kadane\'s Algorithm**\n\n**LETS DRY RUN THIS CODE WITH ONE EXAPMPLE :**\n\nSuppose we have the followi... | 103 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
Simplest Python Solution using Kadane's Algorithm | maximum-subarray | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n\n# Code\n```\nclass Solution:\n def maxSubArray(self, nums: List[int]) -> int:\n maxi = float(\'-inf\')\n temp = 0\n for i in nums:\n temp += i \n maxi = max(maxi,temp)\n temp ... | 1 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
153. Solution | maximum-subarray | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing Kadan\'s Algorithm\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space... | 1 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
Very Easy 100% (Fully Explained)(Java, C++, Python, JavaScript, C, Python3) | maximum-subarray | 1 | 1 | # **Java Solution (Dynamic Programming Approach):**\nRuntime: 1 ms, faster than 89.13% of Java online submissions for Maximum Subarray.\n```\nclass Solution {\n public int maxSubArray(int[] nums) {\n // Initialize currMaxSum & take first element of array from which we start to do sum...\n int maxSum = ... | 151 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
pyhton clean & simple ✅ | | kaden algo. O(n) | | beats 93%🔥🔥🔥 | maximum-subarray | 0 | 1 | \n# 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```\nclass Solution:\n def maxSubArray(self, nums: List[int]) -> int:\n s = 0 \n maxi = -10001\n \... | 4 | Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:**
**Input:** nums = \[1\]
**Output:** 1
**Explanation:** The subarray \... | null |
Binbin the charismatic scientist is back! | spiral-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Binbin the charismatic scientist is back! | spiral-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand | spiral-matrix | 1 | 1 | **!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers. I planned to give for next 10,000 Subscribers as well. If you\'re interested **DON\'T FOR... | 215 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand | spiral-matrix | 1 | 1 | **!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers. I planned to give for next 10,000 Subscribers as well. If you\'re interested **DON\'T FOR... | 215 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
✔💯 DAY 404 | BRUTE->BETTER->OPTIMAL->1- LINER | 0MS-100% | | [PYTHON/JAVA/C++] | EXPLAINED 🆙🆙🆙 | spiral-matrix | 1 | 1 | \n# Please Upvote as it really motivates me \uD83C\uDD99\uD83C\uDD99\uD83C\uDD99\n\n\n# BRUTE\n# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\nBrute Force Approach:\n\nUse a ... | 114 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
✔💯 DAY 404 | BRUTE->BETTER->OPTIMAL->1- LINER | 0MS-100% | | [PYTHON/JAVA/C++] | EXPLAINED 🆙🆙🆙 | spiral-matrix | 1 | 1 | \n# Please Upvote as it really motivates me \uD83C\uDD99\uD83C\uDD99\uD83C\uDD99\n\n\n# BRUTE\n# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\nBrute Force Approach:\n\nUse a ... | 114 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Best Java || c++ || Python || JavaScript with 100% beat in both space and time complexity. | spiral-matrix | 1 | 1 | # Intuition\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI made 4 distinct points (& t... | 1 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Best Java || c++ || Python || JavaScript with 100% beat in both space and time complexity. | spiral-matrix | 1 | 1 | # Intuition\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI made 4 distinct points (& t... | 1 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
🐍Python3 simple and easy solution🔥🔥 | spiral-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using property of array**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- there are 4 stages of this problem\n - **1**) pop first row and put as it is\n - **2**) now we need last column in downwards order... | 3 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
🐍Python3 simple and easy solution🔥🔥 | spiral-matrix | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using property of array**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- there are 4 stages of this problem\n - **1**) pop first row and put as it is\n - **2**) now we need last column in downwards order... | 3 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
python 3 solution for spiral matrix one of the most easiest you will never forget | spiral-matrix | 0 | 1 | # UPVOTE \n```\nclass Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:\n res = []\n if len(matrix) == 0:\n return res\n row_begin = 0\n col_begin = 0\n row_end = len(matrix)-1 \n col_end = len(matrix[0])-1\n while (row_begin <= row_e... | 319 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
python 3 solution for spiral matrix one of the most easiest you will never forget | spiral-matrix | 0 | 1 | # UPVOTE \n```\nclass Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:\n res = []\n if len(matrix) == 0:\n return res\n row_begin = 0\n col_begin = 0\n row_end = len(matrix)-1 \n col_end = len(matrix[0])-1\n while (row_begin <= row_e... | 319 | Given an `m x n` `matrix`, return _all elements of the_ `matrix` _in spiral order_.
**Example 1:**
**Input:** matrix = \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\]
**Output:** \[1,2,3,6,9,8,7,4,5\]
**Example 2:**
**Input:** matrix = \[\[1,2,3,4\],\[5,6,7,8\],\[9,10,11,12\]\]
**Output:** \[1,2,3,4,8,12,11,10,9,5,6,7\]
**Const... | Well for some problems, the best way really is to come up with some algorithms for simulation. Basically, you need to simulate what the problem asks us to do. We go boundary by boundary and move inwards. That is the essential operation. First row, last column, last row, first column and then we move inwards by 1 and th... |
Easy O(n) without dp | jump-game | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 27 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Binbin little princess is back with her knight | jump-game | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Beats 98% || Mind blowing intuition explained | jump-game | 0 | 1 | # Intuition\nChange the destination point backwards. \n# Approach\nInitially, first destination point is last index. Change destination point to index of first previous element that can jump to current goal. That way we can, tecnically, consider this new goal as destination point cause once we can reach to it we can au... | 30 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Very Easy 100%(Fully Explained)(Java,C++, Python, JS, C, Python3) | jump-game | 1 | 1 | # **Java Solution:**\n```\nclass Solution {\n public boolean canJump(int[] nums) {\n // Take curr variable to keep the current maximum jump...\n int curr = 0;\n // Traverse all the elements through loop...\n for (int i = 0; i < nums.length; i++) {\n // If the current index \'i\... | 107 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Use a counter to count on your step! | jump-game | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key mindset here is to use a counter to count on residual steps.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake k as your residual steps. Everytime you move, k-1. If nums[i] offers you more steps, take it! ... | 7 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Python DP + Memo solution | jump-game | 0 | 1 | # Approach\nCreate an array containing information whether you can get to the i-th position.\nWe can simply go through all elements of the array and then iterate over all possible jump lengths updating information in our boolean array.\n\n# Complexity\n- Time complexity: $$O(nk)$$, where k is a sum of all jumps (sum of... | 8 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Python Simple Solution || Beats 81.14% | jump-game | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI can start from the finish line and problems only appear when there is a zero\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code uses a greedy approach to iterate from the last index `j` towards the first inde... | 10 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
O(N) & O(1) | jump-game | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def canJump(self, nums: List[int]) -> bool:\n # t.c/s.c -> O(N)/O(1)\n goal = len(nums)-1\n\n for i in range(len(nums)-2,-1,-1):\n if i + nums[i] >= goal:\n goal = i\n return True if goal == 0 else False\n # return goal =... | 1 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Python Every possible solution Greedy, DP, Recurssive | jump-game | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n### Greedy TO(n) SO(1)\nMaintain a reachable variable and update it on every iteration, if we are ahead of reachable that means it\'s not possible. else reachle will be equal to n\n\n### DP TO(n^2) SO(n)\nUsing a 1d array to mark evry rea... | 6 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Python dynamic programming solution | jump-game | 0 | 1 | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution:\n def canJump(self, nums: List[int]) -> bool:\n i = 1\n prev = nums[0]\n if len(nums) == 1:\n return True\n if prev == 0:\n return False\n while i < len(num... | 1 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Python3 Deadly easy code only 9 lines beats 94.08% in runtime | jump-game | 0 | 1 | \n\n\n# Code\n```\nclass Solution:\n def canJump(self, nums: List[int]) -> bool:\n if len(nums) == 1:return True\n i = 0;j = i\n for i in range(100000):\n if j > i+nums[i]... | 4 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Simple recursive solution | time beats 95.86% | jump-game | 0 | 1 | # Approach\nConsider a variable last_index that points to the element which we are trying to reach. Initialize it to len(nums) - 1.\nRecursively traverse from las_index towards the beginning of the array, searching for the index from which the last_index is reachable. \nIf the last_index is reachable from a preceding i... | 1 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
C++ - Easiest Beginner Friendly Sol || Greedy || O(n) time and O(1) space | jump-game | 1 | 1 | # Intuition of this Problem:\n<!-- Describe your first thoughts on how to solve this problem. -->\n**NOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Approach for this Problem:\n1. Initialize a variable reach to 0, which represen... | 27 | You are given an integer array `nums`. You are initially positioned at the array's **first index**, and each element in the array represents your maximum jump length at that position.
Return `true` _if you can reach the last index, or_ `false` _otherwise_.
**Example 1:**
**Input:** nums = \[2,3,1,1,4\]
**Output:** t... | null |
Solution | merge-intervals | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n \n if(intervals.size()==1)\n return intervals;\n vector<pair<int,int>> p;\n for(int i=0;i<intervals.size();i++)\n {\n p.push_back({intervals[i][0],intervals[i][1]});\n ... | 482 | Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
**Example 1:**
**Input:** intervals = \[\[1,3\],\[2,6\],\[8,10\],\[15,18\]\]
**Output:** \[\[1,6\],\[8,10\],\[15,18\]\... | null |
Ex-Amazon explains a solution with a video, Python, JavaScript, Java and C++ | merge-intervals | 1 | 1 | # My youtube channel - KeetCode(Ex-Amazon)\nI create 158 videos for leetcode questions as of April 28, 2023. I believe my channel helps you prepare for the coming technical interviews. Please subscribe my channel!\n\n### Please subscribe my channel - KeetCode(Ex-Amazon) from here.\n\n**I created a video for this questi... | 27 | Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
**Example 1:**
**Input:** intervals = \[\[1,3\],\[2,6\],\[8,10\],\[15,18\]\]
**Output:** \[\[1,6\],\[8,10\],\[15,18\]\... | null |
[Python3] Sort O(Nlog(N)) | merge-intervals | 0 | 1 | ```\nintervals [[1, 3], [2, 6], [8, 10], [15, 18]]\nintervals.sort [[1, 3], [2, 6], [8, 10], [15, 18]]\n\ninterval = [1,3]\nmerged =[]\nnot merged:\n\tmerged =[ [1,3] ]\n\ninterval =[2,6]\nmerged = [ [1,3] ]\nmerged[-1][-1] = 3 > interval[0] = 2:\n\tmerged[-1][-1] = max(merged[-1][-1] = 3 ,interval[-1] = 6) =6\nmerged ... | 182 | Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
**Example 1:**
**Input:** intervals = \[\[1,3\],\[2,6\],\[8,10\],\[15,18\]\]
**Output:** \[\[1,6\],\[8,10\],\[15,18\]\... | null |
Binbin is not guade | merge-intervals | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
**Example 1:**
**Input:** intervals = \[\[1,3\],\[2,6\],\[8,10\],\[15,18\]\]
**Output:** \[\[1,6\],\[8,10\],\[15,18\]\... | null |
binbin is guade | merge-intervals | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an array of `intervals` where `intervals[i] = [starti, endi]`, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
**Example 1:**
**Input:** intervals = \[\[1,3\],\[2,6\],\[8,10\],\[15,18\]\]
**Output:** \[\[1,6\],\[8,10\],\[15,18\]\... | null |
SIMPLE STRAIGHTFORWARD PYTHON (BEATS 93%) | insert-interval | 0 | 1 | \n# Approach\n1. Append new interval into `intervals`\n2. Sort `intervals` by starting times (default sort behavior)\n3. Append to `ans` if `ans` is empty or if the current start time is greater than the last time, indicating no overlap and meaning we need to add a new interval\n4. Or update last `ans` end time if the ... | 1 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Detailed solution in Python3/Go/Ts with O(n) time and space complexity | insert-interval | 0 | 1 | # Intuition\n\nAs we iterate through the intervals we only need to merge intervals that overlap each other and insert our new interval if it ends before the next iterated interval\n\n# Approach\n\nWe begin by creating an empty list which will contain our final **output**.\n\nIterate through all of the provided `interva... | 6 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Python Super Short, Simple & Clean Solution 99% faster | insert-interval | 0 | 1 | the main idea is that when iterating over the intervals there are three cases:\n\n1. the new interval is in the range of the other interval\n2. the new interval\'s range is before the other\n3. the new interval is after the range of other interval\n\n```\nclass Solution:\n def insert(self, intervals: List[List[int]]... | 114 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Simple Python solution using insort | insert-interval | 0 | 1 | \n# Code\n```\nclass Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n insort(intervals, newInterval)\n ans = [intervals[0]]\n for s, e in intervals[1:]:\n if ans[-1][-1] >= s:\n ans[-1][-1] = max(ans[-1][-1], e)\n ... | 3 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
57. Insert Interval with step by step explanation | insert-interval | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. First, we handle the edge case where intervals is empty by returning [newInterval].\n2. Then, we use binary search to find the right place to insert newInterval into intervals.\n3. Next, we initialize a result list with t... | 2 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Simple Python Solution | TC: O(N) | SC: O(N) | insert-interval | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize an empty result array.\n2. Iterate through the existing intervals and compare the start and end times of each interval with the start and end times of th... | 1 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Python Binary search | insert-interval | 0 | 1 | # Complexity\n- Time complexity:\nStill $$O(n)$$ for bad worse cases.\n\n\n# Code\n```\nclass Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n i = bisect.bisect_left(intervals, newInterval)\n res = intervals[:i]\n \n if res and newInte... | 1 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
✅ Explained - Simple and Clear Python3 Code✅ | insert-interval | 0 | 1 | \n# Approach\nThe solution follows the logic of iterating through the intervals to find the correct position to insert the new interval while maintaining the sorted order. After insertion, it iterates over the modified array to merge any overlapping intervals by updating the end time of the previous interval if necessa... | 9 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Easiest Solution | insert-interval | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
Python3 || 79 ms, faster than 93.12% of Python3 || Clean and Easy to Understand | insert-interval | 0 | 1 | ```\ndef insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n result = []\n for i in range(len(intervals)):\n if newInterval[1] < intervals[i][0]:\n result.append(newInterval)\n return result + intervals[i:]\n elif newIn... | 16 | You are given an array of non-overlapping intervals `intervals` where `intervals[i] = [starti, endi]` represent the start and the end of the `ith` interval and `intervals` is sorted in ascending order by `starti`. You are also given an interval `newInterval = [start, end]` that represents the start and end of another i... | null |
[VIDEO] Step-by-Step Explanation - Traverse from Back | length-of-last-word | 0 | 1 | https://youtu.be/rxb7umOJScc?si=bc9dzIPqjSn9davE\n\nOne way of solving this would be to use the `split()` method to split the string on whitespaces, then return the length of the last word in the array:\n```\narray = s.split()\nreturn len(array[-1])\n```\nHowever, this is inefficient because you have to split on <i>eve... | 8 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
Easy Python Solution with Briefly Explanation ✅✅ | length-of-last-word | 0 | 1 | # Approach\nThis code defines a class `Solution` with a method `lengthOfLastWord` that calculates the length of the last word in a given input string `s`. Here\'s a brief explanation of each part of the code:\n\n1. `stripped = s.strip()`: This line removes leading and trailing whitespace from the input string `s` using... | 15 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
Python3 Two Liner beats 97.14% 🚀 with Explanation | length-of-last-word | 0 | 1 | # Approach\n- First we will convert given String of words into array of strings on basis of white spaces using python\'s `.split()` which converts the string into Array \n\n- for example:\n```\nstr = "Hello World"\narr = str.split()\n\n# arr will be\narr = ["Hello" , "World"]\n```\n- So we will just return the length o... | 9 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
phew! by13 year old boy( solution) | length-of-last-word | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
Simple Python solution | length-of-last-word | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
Simple method in two line | length-of-last-word | 0 | 1 | this is the one of the easiest method for beginners\nclass Solution:\n def lengthOfLastWord(self, s: str) -> int:\n word_list=s.split()\n return len(word_list[-1])\n \n``` | 0 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
🌺C# ,Java ,Python3, JavaScript solutions ( iteration or trim ) | length-of-last-word | 1 | 1 | The easist way may be iterate from the end of the string, can we do that with a different way?\n**Of course !**\n\n\u2B50**See more Code and Explanation : [https://zyrastory.com/en/coding-en/leetcode-en/leetcode-58-length-of-last-word-solution-and-explanation-en/](https://zyrastory.com/en/coding-en/leetcode-en/leetcode... | 15 | Given a string `s` consisting of words and spaces, return _the length of the **last** word in the string._
A **word** is a maximal substring consisting of non-space characters only.
**Example 1:**
**Input:** s = "Hello World "
**Output:** 5
**Explanation:** The last word is "World " with length 5.
**Example 2:**
... | null |
PYTHON3 || SIMPLE TO UNDERSTAND SOLUTION || 100% WORKING | spiral-matrix-ii | 0 | 1 | # Code\n```\nclass Solution:\n def generateMatrix(self, n: int) -> List[List[int]]:\n res = [[0]*n for i in range(n)]\n if n < 2:\n res[0][0]=1\n return res\n else:\n track = 1\n cycle = 1\n k = 0\n i = 0\n while k < n:... | 1 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Enchanting Spiral Matrix Generation: Unveiling the Elegance of Python Magic! | spiral-matrix-ii | 0 | 1 | # Spiral Matrix Generation\n\n## Intuition\nThe code generates a 2D matrix of size `n x n` in a spiral order, starting from the top-left corner and moving in a clockwise direction.\n\n## Approach\n1. Initialize variables to keep track of the total number of elements (`total`), the current count (`count`), and the start... | 1 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Binbin golden again today! Big big applause for her! | spiral-matrix-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Simple Python Solution | spiral-matrix-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Python short and clean. Iterative solution. | spiral-matrix-ii | 0 | 1 | # Approach\n1. Reuse the `inwards_spiral` function from [Spiral Matrix I](https://leetcode.com/problems/spiral-matrix/solutions/1467615/python-short-and-clean-iterative-solution/?orderBy=most_votes) to generate indices in spiral order.\n\n2. Zip through indices and counter, assigning count to the corresponding index of... | 2 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
🔥🔥Easy Solution Using 4 Pointers!!🔥🔥 | spiral-matrix-ii | 0 | 1 | # Intuition\nWe have to make a matrix then traverse it spirally!\n\n# Approach\nFirst of all we have to create a 2-D matrix of size NxN and assign each cell with value 1. Then after that we have to start traversing it spirally and while traversing each cell we have to calculate its value from its previous cell.\n\n# Co... | 1 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand | spiral-matrix-ii | 1 | 1 | **!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers. I planned to give for next 10,000 Subscribers as well. If you\'re interested **DON\'T FOR... | 61 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
✔💯 DAY 405 | BRUTE->BETTER->OPTIMAL->3-LINER | 0MS-100% | | [PYTHON/JAVA/C++] | EXPLAINED 🆙🆙🆙 | spiral-matrix-ii | 1 | 1 | \n\n# Please Upvote as it really motivates me \uD83C\uDD99\uD83C\uDD99\uD83C\uDD99\n\n\n\n# BRUTE\nThe brute force solution to generate a matrix in spiral order is to simulate the process of filling the mat... | 46 | Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n2` in spiral order.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1,2,3\],\[8,9,4\],\[7,6,5\]\]
**Example 2:**
**Input:** n = 1
**Output:** \[\[1\]\]
**Constraints:**
* `1 <= n <= 20` | null |
Simplest solution | BEATS 94.5% | permutation-sequence | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n total, ret, digits = 1, "", [i for i in range(1, n+1)]\n for i in range(2, n):\n... | 1 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Easy Python Implementation: Beat 88% in time. | permutation-sequence | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConsider the example: n = 3, k = 3. The result is 213. Let\'s think about how to obtain 213 given k=3. The total number of permutation is n! = 3! = 6. \n\n**Observatio... | 1 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Solution | permutation-sequence | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v={0};\n int tmp=1;\n for(int i=1;i<=n;i++){\n v.push_back(i);\n tmp*=i;\n }\n string s;\n cout<<tmp<<" ";\n for(int i=n;i>=2;i--){\n tmp/=i;\n ... | 23 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Beats 99.7% 60. Permutation Sequence with step by step explanation | permutation-sequence | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nHere, we use a simple factorial approach. First, we calculate all the factorials up to n, and use that to find the next number to add to the result. We start from the last factorial and keep adding numbers to the result, dec... | 2 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Most optimal solution without using recursion and backtracking with complete exaplanation | permutation-sequence | 1 | 1 | \n\n# Approach\nThe given solution aims to find the kth permutation sequence of numbers from 1 to n. It uses a mathematical approach to determine the digits of the kth permutation by repeatedly calculating the factorial of (n-1), identifying the next digit in the permutation, and updating the remaining digits.\n\nHere\... | 3 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
1 Liner Code 😎 | Python | permutation-sequence | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Using the `Permutations` to find all the possible permutations.\n2. Sorting in the ascending order.\n3. Getting the `k-1` th value, which is a tuple\n4. Converting that tuple in string format.\n5. Returning the result.\n\n# Code\n```\n... | 3 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Python With Recursion | permutation-sequence | 0 | 1 | # Intuition\nThe intuition behind this code is to find the k-th permutation of numbers from 1 to n. To understand the intuition, let\'s break down the approach step by step:\n\n\n\nThe key insight here is to break down the problem into smaller subproblems by calculating `offset` and determining how many times to "skip"... | 1 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Python || 99.74% Faster || Easy || Recursion | permutation-sequence | 0 | 1 | ```\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n def solve(arr,k,n,ans):\n if n==1:\n ans+=str(arr[0])\n return ans\n f=factorial(n-1)\n ind=k//f\n ans+=str(arr[ind])\n arr.pop(ind)\n k%=f\... | 1 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Python ✅- beats 98%- Easy&Optimum Solution | permutation-sequence | 0 | 1 | **This is optimum question **\n```\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n s=[]\n for i in range(n):\n s.append(str(i+1))\n \n def fun(s,k,l):\n p=[]\n fact=factorial(l)\n #print(fact)\n while (s!=[]): \n... | 2 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Python3 Solution Explained With a Tip For Faster Execution | Beats 99.8% | permutation-sequence | 0 | 1 | My solution is basically the same with the many others but here is another explanation:\n\nLet\'s go over an example:\n```\nn=4 k=9\n1234 ------ start here\n1243 ------ third digit changes here \n1324 ------ second digit changes here \n1342\n1423\n1432 \n2134 ------ first digit changes here \n2143\n2314 -> k=9\n2341\n... | 15 | The set `[1, 2, 3, ..., n]` contains a total of `n!` unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:
1. `"123 "`
2. `"132 "`
3. `"213 "`
4. `"231 "`
5. `"312 "`
6. `"321 "`
Given `n` and `k`, return the `kth` permutation sequence.
**Exa... | null |
Best Python Solution || O(N) Time Beats 90% || Two Pointers | rotate-list | 0 | 1 | # Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe create two pointers f and s initially we send f to k moves forward. If k exceeds the length of list then we take k % length to get the exact number of moves f should move. And finally we start moving both s and f until f reaches the end... | 1 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
[96% faster] Simple python solution with explanation | rotate-list | 0 | 1 | Please upvote if you liked the solution \n\n\n```\n\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 rotateRight(self, head: ListNode, k: int) -> ListNode:\n \n if not head:\n r... | 321 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Simple and Elegant Python Solution | rotate-list | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor this problem it tells us that we want to rotate right k times. This tells us that after the end of k right rotations, the tail of the new linked list should be the node k elements from the end of the original linked list. \n\n\n# Appr... | 1 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Python 3 recursive solution | rotate-list | 0 | 1 | \n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def rotateRight(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:\n if not head: return head\n\n if... | 1 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Best Python Solution || O(N) Time Beats 90% || Two Pointers | rotate-list | 0 | 1 | # Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe create two pointers f and s initially we send f to k moves forward. If k exceeds the length of list then we take k % length to get the exact number of moves f should move. And finally we start moving both s and f until f reaches the end... | 2 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Easy to understand explained linear solution | rotate-list | 0 | 1 | # Intuition\n- pointer approach\n- connect end and start\n- and break at k\n\n\n# Approach\n- if n=0 or 1 or k=0 just return head bcuz it cant be rotated\n- calculate lengh of linkedlist\n- now mod k by n bcuz rotaion by n gives the given rotation only\n- now connect last node to first node\n- now travel current till n... | 2 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Runtime : Beats 71.05%✅ /// Memory : Beats 51.16%✅ | rotate-list | 0 | 1 | # Complexity\n- Time complexity:\nO(n) + O(k)\n\n- Space complexity:\nO(1)\n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def rotateRight(self, head: Optional[ListNode], k: i... | 2 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
✅ 🔥 Python3 || ⚡easy solution | rotate-list | 0 | 1 | \n```\nclass Solution:\n def rotateRight(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:\n if head is None or head.next is None or k == 0:\n return head\n \n # Obtener la longitud de la lista enlazada\n length = 0\n itr = head\n while itr:\n ... | 1 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
✅ [Python] | [VISUAL] | Easy to Understand | O(N) Time | O(1) Space | rotate-list | 0 | 1 | \uD83D\uDD3A**Please UPVOTE: Can we hit 20?** \uD83D\uDD3A\n\n**Approach**\nHere we modify the linked list in place by visiting the last node and then moving a certain number of nodes to find the new head of the linked list. The example below shows a visual of the algorithm working on the given example [1,2,3,4,5] k=2... | 58 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
61. Rotate List with step by step explanation | rotate-list | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. If the head is None or the head.next is None, return head, because there is no need to rotate.\n2. Get the length of the linked list and the tail node.\n3. Get the kth node from the beginning, which is the new head.\n4. C... | 2 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Yahooooo Binbin loves linked list, much understandable than (> >) tree | rotate-list | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
✔️ [Python3] ROTATE ( •́ .̫ •̀ ), Explained | rotate-list | 0 | 1 | **UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nFirst of all, we notice that `k` can be greater than the length of the list. In this case, rotations will be repeated. To avoid useless operations, we convert `k` as follows: `k = k % length` (if `k` is equal to the ... | 27 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Solution of the probem in Python | rotate-list | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\... | 1 | Given the `head` of a linked list, rotate the list to the right by `k` places.
**Example 1:**
**Input:** head = \[1,2,3,4,5\], k = 2
**Output:** \[4,5,1,2,3\]
**Example 2:**
**Input:** head = \[0,1,2\], k = 4
**Output:** \[2,0,1\]
**Constraints:**
* The number of nodes in the list is in the range `[0, 500]`.
* ... | null |
Clear Explanation with Images || Python || Very Easy to Understand | rotate-list | 0 | 1 | \n\n\n\n. The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
✅ 98.83% Easy DP & Math | unique-paths | 1 | 1 | # Interview Guide - Unique Paths in a Grid\n\n## Problem Understanding\n\nThe problem describes a robot situated on a $$ m \\times n $$ grid, starting at the top-left corner (i.e., $$ \\text{grid}[0][0] $$). The robot can move either to the right or downwards at any given time, and the objective is to reach the bottom-... | 113 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
✅Step by step🔥Beginner Friendly🔥||DP||✅3 Approaches||full explanation🔥|| DP | unique-paths | 1 | 1 | # Question Understanding-\n\n**Given are only two valid moves :**\n- **Move right**\n- **Move down**\nHence, it is clear number of paths from cell (i,j) = sum of paths from cell( i+1,j) and cell(i,j+1)\n\n**It becomes a DP problem.**\nBut implementing DP directly **will lead to TLE**.\n**So memoization is useful -> Sto... | 103 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
testing123 | unique-paths | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ntesting123\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDynamic programming approach where we save the count of the possible paths that past through each index. \n# Complexity\n- Time complexity:\n<!-- Add your ... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Top-Down Dynamic Programming in Python3 | unique-paths | 0 | 1 | # Intuition\nThe problem description is the following: \n\n- there\'s a robot, that\'s standing at (0, 0)\n- our goal is to calculate **HOW** many **UNIQUE** paths can we explore by moving robot at directions\n\n\n---\n\n\nLets consider an example:\n```py\ngrid = [[R, 0]\n [0, 0]]\n# starting point is (0, 0)\n# ... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Paths | unique-paths | 1 | 1 | # Intuition\nWhen first encountering this problem, my initial thought was to approach it using dynamic programming. I recognized that this is a classic problem of finding the number of unique paths from the top-left corner to the bottom-right corner of a grid, where you can only move down or to the right. \n\n# Approac... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Python easy solutions | unique-paths | 0 | 1 | # Intuition\n\n\n# Approach\nm*n = 3*7\n[28, 21, 15, 10, 6, 3, 1] 0\n[7, 6, 5, 4, 3, 2, 1] 0\n[1, 1, 1, 1, 1, 1, 1] 0\n 0 0 0 0 0 0 0\n\nWe see this matrix, that assign 1\'s to bottom row and right most column. Then in reverse direction sum up thr right ane down value.\nThat is at place 5*1 we have 1 ... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
python3 easy beats 7% | unique-paths | 0 | 1 | # Code\n```\nclass Solution:\n def uniquePaths(self, m: int, n: int) -> int:\n #bottom additional row of all the ones\n oldrow = [1]*n\n for i in range(m-1):\n #for each row we are calculating newrow\n newrow = [1]*n\n #traverse through columns in reverse order e... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Binbin solved this question at light speed! | unique-paths | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
4 Different Approaches---->DP | unique-paths | 0 | 1 | # 1. Recursive Approach-------->Top to Down\n```\nclass Solution:\n def uniquePaths(self, m: int, n: int) -> int:\n def solve(ind1,ind2):\n if ind1==0 and ind2==0:\n return 1\n if ind1<0 or ind2<0:\n return 0\n return solve(ind1-1,ind2)+solve(ind... | 5 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Python| binomial coefficients | n+m choose n (or m) | formula with factorial | unique-paths | 0 | 1 | # Intuition\n\n\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n def uniquePaths(self, m: int, n: int) -> int:\n\n d... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Python || Dynamic Programming || BackTracking 🔥 | unique-paths | 0 | 1 | # Code\n```\nclass Solution:\n def uniquePaths(self, m: int, n: int) -> int:\n dp = [[0]*101 for i in range(101)]\n def count(r,c):\n if r == 1 or c == 1:\n return 1\n if dp[r][c]:\n return dp[r][c]\n left = count(r - 1, c)\n rig... | 1 | There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
Given the two integers `m` and `n`, return _the nu... | null |
Python3 Solution | unique-paths-ii | 0 | 1 | \n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n m=len(obstacleGrid)\n n=len(obstacleGrid[0])\n dp=[[0 for _ in range(n)] for _ in range(m)]\n for col in range(n):\n if obstacleGrid[0][col]==1:\n break\n ... | 3 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.