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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
find-the-count-of-monotonic-pairs-i | Using 3D Dp | using-3d-dp-by-venkatarohit_p-4rue | 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 | venkatarohit_p | NORMAL | 2024-08-12T03:53:21.158234+00:00 | 2024-08-12T03:53:21.158258+00:00 | 13 | false | # 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)$$ --... | 0 | 0 | ['Java'] | 0 |
find-the-count-of-monotonic-pairs-i | [python3] simple dp | python3-simple-dp-by-vl4deee11-1daw | \nclass Solution:\n def countOfPairs(self, nums: List[int]) -> int:\n @cache\n def dp(la,i):\n if i>=len(nums):return 1\n | vl4deee11 | NORMAL | 2024-08-12T03:21:25.618567+00:00 | 2024-08-12T03:26:39.297491+00:00 | 1 | false | ```\nclass Solution:\n def countOfPairs(self, nums: List[int]) -> int:\n @cache\n def dp(la,i):\n if i>=len(nums):return 1\n a=0\n lb=nums[i-1]-la if la!=-1 else -1\n for na in range(la if la!=-1 else 0,nums[i]+1):\n nb=nums[i]-na\n ... | 0 | 0 | [] | 0 |
find-the-count-of-monotonic-pairs-i | trivial dp solution | trivial-dp-solution-by-sovlynn-j87b | Intuition\nThis is a typical dp problem. Let $dp_i[n]$ be the solution which the increasing ends with $n$ and the decreasing ends with $num[i]-n$, we have.\n\nd | sovlynn | NORMAL | 2024-08-12T02:07:47.065694+00:00 | 2024-08-12T08:25:34.555646+00:00 | 13 | false | # Intuition\nThis is a typical dp problem. Let $dp_i[n]$ be the solution which the increasing ends with $n$ and the decreasing ends with $num[i]-n$, we have.\n\n$$dp_i[n]=\\sum_j^{j\\leq n &&nums[i-1]-j\\geq nums[i]-i}dp_{i-1}[j]$$\n\nThat is, for all prev pairs $(j, nums[i-1]-j)$, it should fullfill the increasing or ... | 0 | 0 | ['Dynamic Programming', 'Prefix Sum', 'Rust'] | 0 |
find-the-count-of-monotonic-pairs-i | [C++] 2D-DP problem, consider every sub-problems | c-2d-dp-problem-consider-every-sub-probl-gxq2 | Intuition\n Describe your first thoughts on how to solve this problem. \nFor every arr1[i], take one number from [1,50] and caclulate the rest\n\n# Approach\n D | tony2037 | NORMAL | 2024-08-11T22:48:33.151253+00:00 | 2024-08-11T22:48:33.151314+00:00 | 14 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor every `arr1[i]`, take one number from `[1,50]` and caclulate the rest\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n`dp[i][s]`: the number of pairs for `nums[i:]` when `arr1[i-1] == s`\ngiven a choice `x` (fr... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Java 2D DP | java-2d-dp-by-sarvesh412-lx8j | 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 | sarvesh412 | NORMAL | 2024-08-11T22:19:02.241087+00:00 | 2024-08-11T22:19:02.241119+00:00 | 1 | false | # 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)$$ --... | 0 | 0 | ['Java'] | 0 |
find-the-count-of-monotonic-pairs-i | Java 3D DP | java-3d-dp-by-robertskonieczny-q30x | There are more elegant solutions, but this is mine.\n\njava\nclass Solution {\n private int[][][] memo;\n public int countOfPairs(int[] nums) {\n t | robertskonieczny | NORMAL | 2024-08-11T21:15:55.898794+00:00 | 2024-08-11T21:15:55.898824+00:00 | 9 | false | There are more elegant solutions, but this is mine.\n\n```java\nclass Solution {\n private int[][][] memo;\n public int countOfPairs(int[] nums) {\n this.memo = new int[nums.length][51][51];\n for (int[][] rowrow : memo) for (int[] row : rowrow) Arrays.fill(row, -1);\n return dp(nums, 0, 0, n... | 0 | 0 | ['Java'] | 0 |
find-the-count-of-monotonic-pairs-i | [C++] Top-down DP Solution | c-top-down-dp-solution-by-samuel3shin-b7rt | Code\n\nclass Solution {\npublic:\n int N;\n const int MOD = 1e9 + 7;\n unordered_map<int, int> memo;\n\n int getKey(int idx, int prev1, int prev2) | Samuel3Shin | NORMAL | 2024-08-11T20:09:56.243445+00:00 | 2024-08-11T20:09:56.243465+00:00 | 9 | false | # Code\n```\nclass Solution {\npublic:\n int N;\n const int MOD = 1e9 + 7;\n unordered_map<int, int> memo;\n\n int getKey(int idx, int prev1, int prev2) {\n return idx*50*50 + prev1*50 + prev2;\n }\n\n int helper(vector<int>& nums, int idx, int prev1, int prev2) {\n if(idx==N) return 1;\... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Dynamic Programming Easy Solution | dynamic-programming-easy-solution-by-san-sse1 | Approach\nDynamic Programming\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity: O(N3)\n Add your time complexity here, e.g. | SandeepPatel0605 | NORMAL | 2024-08-11T19:45:20.248131+00:00 | 2024-08-11T19:45:20.248157+00:00 | 6 | false | # Approach\nDynamic Programming\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N**3)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n**2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Simple DP C++ | simple-dp-c-by-gps_357-bmda | 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 | gps_357 | NORMAL | 2024-08-11T19:39:58.759717+00:00 | 2024-08-11T19:39:58.759738+00:00 | 6 | false | # 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:O(2500*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(50*n)\n<!-- Add your space complexity here, ... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Easy | Most intuitive approach | easy-most-intuitive-approach-by-gaurav_5-8ddj | 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 | gaurav_592 | NORMAL | 2024-08-11T18:59:36.660718+00:00 | 2024-08-11T18:59:36.660753+00:00 | 8 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | ✅Simple recursive solution | simple-recursive-solution-by-akash_sonar-8h4l | Intuition\nIf a + b = c , then if we choose a = x then b = c-x. We just simply brute force all possiblities recursively and check if we can form c. To avoid TLE | Akash_Sonar | NORMAL | 2024-08-11T18:36:27.066817+00:00 | 2024-08-11T18:36:27.066859+00:00 | 14 | false | # Intuition\nIf `a + b = c` , then if we choose `a = x` then `b = c-x `. We just simply brute force all possiblities recursively and check if we can form `c`. To avoid **TLE** we use memoization.\n\n\n# Complexity\n- Time complexity:\nO(2000 * 50)\n\n- Space complexity:\nO(n * 50 * 50)\n\n# Code\n```\nclass Solution {\... | 0 | 0 | ['Memoization', 'Java'] | 0 |
find-the-count-of-monotonic-pairs-i | Go, concise | go-concise-by-gvnpl-y9oa | \nvar h map[int]map[int]int\n\nfunc solve(nums []int, i int, prevInc int) int {\n if i == len(nums) {\n return 1\n }\n if m, ok := h[i]; ok {\n | gvnpl | NORMAL | 2024-08-11T16:52:03.560680+00:00 | 2024-08-11T16:52:03.560710+00:00 | 1 | false | ```\nvar h map[int]map[int]int\n\nfunc solve(nums []int, i int, prevInc int) int {\n if i == len(nums) {\n return 1\n }\n if m, ok := h[i]; ok {\n if v, ok := m[prevInc]; ok {\n return v\n }\n } else {\n h[i] = map[int]int{}\n }\n ans := 0\n \n for inc := p... | 0 | 0 | ['Dynamic Programming', 'Go'] | 0 |
find-the-count-of-monotonic-pairs-i | [Backtracking-> DP] Python Beats 100% on time | Interview Though Process | backtracking-dp-python-beats-100-on-time-hsoq | Intuition\n\nThe most brute force way ( also backtracking solution) is to try every possible combination of numebrs on each index, from left to right and once | satyamsaini97 | NORMAL | 2024-08-11T16:02:54.370600+00:00 | 2024-08-11T16:02:54.370630+00:00 | 41 | false | # Intuition\n\nThe most brute force way ( also backtracking solution) is to try every possible combination of numebrs on each index, from left to right and once you have filled the array, +1 the count. \n\n\n# Code - Backtracking ( TLE)\n```\nclass Solution:\n def countOfPairs(self, nums: List[int]) -> int:\n ... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Python3'] | 0 |
find-the-count-of-monotonic-pairs-i | Math for DP Problem | math-for-dp-problem-by-yanganyi-n2fe | Intuition\n Describe your first thoughts on how to solve this problem. \nthis should be dynamic programming!\n\n# Approach\n Describe your approach to solving t | yanganyi | NORMAL | 2024-08-11T15:47:04.033293+00:00 | 2024-08-11T15:47:04.033350+00:00 | 34 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nthis should be dynamic programming!\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nmathmathmathmathmath\n\nwe first get the values in arr2 by finding `b = i - a` where `a = max(a, i - b)`\n\nwe then perform combi ... | 0 | 0 | ['Python3'] | 0 |
find-the-count-of-monotonic-pairs-i | Easy Memoization Approach | easy-memoization-approach-by-shaanpatel9-f9fu | 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 | shaanpatel9889 | NORMAL | 2024-08-11T15:38:04.742940+00:00 | 2024-08-11T15:38:04.742973+00:00 | 6 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Easy DP with Loop || Full Explanation || NSUT Pro coder | easy-dp-with-loop-full-explanation-nsut-i14la | Intuition & Approach\nWhen Question asked to find all possible sub arrays it means we have to ry every combination which basically means DP.\n\nNow when you ana | beastgm10 | NORMAL | 2024-08-11T14:48:40.589190+00:00 | 2024-08-11T14:48:40.589235+00:00 | 10 | false | # Intuition & Approach\nWhen Question asked to find all possible sub arrays it means we have to ry every combination which basically means DP.\n\nNow when you analyse the conditions given, we can figure out that loop is required in this case to check all cases.\n\nFor ease first write the recurrsive code then memoize i... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Golang solution | golang-solution-by-comp1exo-86oj | Intuition\n Describe your first thoughts on how to solve this problem. \ni referred this video as i have problem framing solution while attempting in contest \n | comp1exo | NORMAL | 2024-08-11T14:29:01.310877+00:00 | 2024-08-11T14:29:01.310918+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ni referred this video as i have problem framing solution while attempting in contest \nvideo link : https://www.youtube.com/watch?v=2VkxY6a8z8g\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time c... | 0 | 0 | ['Go'] | 0 |
find-the-count-of-monotonic-pairs-i | Java Memorization using 2D array| Beasts 100% Runtime | java-memorization-using-2d-array-beasts-359x2 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n- left+right=nums[i];\n- so, if we keep on iteration left and to valida | harish_hk | NORMAL | 2024-08-11T12:23:47.169929+00:00 | 2024-08-11T12:23:47.169952+00:00 | 16 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach\n- left+right=nums[i];\n- so, if we keep on iteration left and to validated right is decreasing\nget prevRight by ( nums[i-1]-leftPrev)\n\n- left=PrevLeft;\n- i=newLeft;\n- so new Right should be lesser than prevRight\n```\... | 0 | 0 | ['Java'] | 0 |
find-the-count-of-monotonic-pairs-i | DP | dp-by-aman_mangukiya-262b | Intuition : Dp\n Describe your first thoughts on how to solve this problem. \n\n\n# Complexity\n- Time complexity: ~O(n^3)\n Add your time complexity here, e.g. | Aman_mangukiya | NORMAL | 2024-08-11T12:09:49.340161+00:00 | 2024-08-11T12:09:49.340192+00:00 | 3 | false | # Intuition : Dp\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Complexity\n- Time complexity: ~O(n^3)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: ~O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define mod 1000000007\nclass ... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | beginner friendly memoization using 2d dp | beginner-friendly-memoization-using-2d-d-mc4r | class Solution {\n public int mod = (int)1e9+7;\n public int countOfPairs(int[] nums) {\n int maxi = 0 ; \nfor(int i = 0 ; i< nums.length ; i++) | shivanshuagrawal | NORMAL | 2024-08-11T12:05:50.679339+00:00 | 2024-08-11T12:05:50.679370+00:00 | 9 | false | class Solution {\n public int mod = (int)1e9+7;\n public int countOfPairs(int[] nums) {\n int maxi = 0 ; \nfor(int i = 0 ; i< nums.length ; i++){\nmaxi = Math.max(maxi,nums[i]);\n}\nint dp[][] = new int[nums.length+1][maxi+1];\nfor(int x[] : dp) Arrays.fill(x,-1);\nreturn memoization(nums,dp,0,0 ,50);\n... | 0 | 0 | ['Array', 'Java'] | 0 |
find-the-count-of-monotonic-pairs-i | 2d memoization dp || O(n*51*51) || c++ | 2d-memoization-dp-on5151-c-by-sarthakrau-po0f | 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 | sarthakrautelanew | NORMAL | 2024-08-11T11:16:23.026106+00:00 | 2024-08-11T11:16:23.026137+00:00 | 12 | false | # 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)$$ -->\no(n*51*51)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 0 |
find-the-count-of-monotonic-pairs-i | C++ | DP solution | c-dp-solution-by-mihirb77-v7fz | 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 | mihirb77 | NORMAL | 2024-08-11T11:12:52.880175+00:00 | 2024-08-11T11:12:52.880204+00:00 | 10 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
find-the-count-of-monotonic-pairs-i | Contest 410 || DP | contest-410-dp-by-sajaltiwari007-0dec | Approach and Intuition\n\nThe problem appears to be related to counting valid sequences or pairs based on certain constraints. The approach used is dynamic prog | sajaltiwari007 | NORMAL | 2024-08-11T11:07:08.366103+00:00 | 2024-08-11T11:07:08.366136+00:00 | 8 | false | ### Approach and Intuition\n\nThe problem appears to be related to counting valid sequences or pairs based on certain constraints. The approach used is dynamic programming (DP) to solve the problem.\n\n#### Intuition:\n1. **Dynamic Programming Table (`dp`)**: \n - The `dp` array is a 3D table where `dp[i][a][b]` repr... | 0 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 0 |
find-the-count-of-monotonic-pairs-i | 🔥2D DP | C++| Tabulation | intutive | EASY | 100%Beats 🔥🚩🔥🚩 | 2d-dp-c-tabulation-intutive-easy-100beat-vc4t | 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 | aryan_0510 | NORMAL | 2024-08-11T10:52:21.714853+00:00 | 2024-08-11T10:52:21.714880+00:00 | 10 | false | # 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: O(50*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(50*N)\n<!-- Add your space complexity here... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | ✅ Beginner friendly easy solution ( Image explanation) | beginner-friendly-easy-solution-image-ex-l2xm | Important: If you want to learn and understand the patterns in problems and want to solve them using a single template you should definitely check my youtube ch | rishi800900 | NORMAL | 2023-10-14T16:04:33.897551+00:00 | 2023-10-14T20:08:05.956973+00:00 | 2,396 | false | #### **Important:** If you want to learn and understand the patterns in problems and want to solve them using a single template you should definitely check my youtube channel by clicking my leetcode profile or search "**coding samurai**" on youtube. Template taught: sweepline, sliding window, backtracting and many more... | 27 | 1 | ['Dynamic Programming', 'C'] | 6 |
longest-unequal-adjacent-groups-subsequence-ii | LIS + Parent (Greedy Fail 🔥) || (Easy Video Solution with all scenarios) 🔥 || C++ || JAVA | lis-parent-greedy-fail-easy-video-soluti-tag6 | Intuition\n Describe your first thoughts on how to solve this problem. \nI recommend breaking down the problem into smaller parts and, with small examples, visu | ayushnemmaniwar12 | NORMAL | 2023-10-14T18:11:20.718737+00:00 | 2023-10-14T18:11:20.718761+00:00 | 1,156 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI* recommend breaking down the problem into smaller parts and, with small examples, visually simulate the different scenarios. Consider various ways to solve the problem, and eventually, you\'ll find a solution that works.*\n\n# ***Detail... | 18 | 1 | ['Dynamic Programming', 'Greedy', 'Python', 'C++', 'Java'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | ✅☑[C++/C/Java/Python/JavaScript] || DP || EXPLAINED🔥 | ccjavapythonjavascript-dp-explained-by-m-rn9f | PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n1. The code defines a C++ class named Solution that contains a public funct | MarkSPhilip31 | NORMAL | 2023-10-14T16:21:13.802137+00:00 | 2023-10-14T16:21:13.802167+00:00 | 1,262 | false | # *PLEASE UPVOTE IF IT HELPED*\n\n---\n\n\n# Approaches\n***(Also explained in the code)***\n\n1. The code defines a C++ class named `Solution` that contains a public function `getWordsInLongestSubsequence`.\n1. This function takes three arguments: `n`, an integer, `words`, a vector of strings, and `groups`, a vector o... | 14 | 0 | ['String', 'Dynamic Programming', 'C', 'C++', 'Java', 'Python3', 'JavaScript'] | 4 |
longest-unequal-adjacent-groups-subsequence-ii | Both recursive & iterative approach || Very simple and easy to understand solution | both-recursive-iterative-approach-very-s-bw8v | \n# Approach 1 : (Recursive)\n- Need to check all possible cases\n- While doing so, do memorise the next possible best index from each index. Best idex is the o | kreakEmp | NORMAL | 2023-10-14T17:46:45.723023+00:00 | 2023-10-14T19:46:13.208947+00:00 | 1,657 | false | \n# Approach 1 : (Recursive)\n- Need to check all possible cases\n- While doing so, do memorise the next possible best index from each index. Best idex is the one - when moved to that position we end up in moving to longest length\n- During traversing to a index check if already visited. If yes then add the next indext... | 10 | 3 | ['Dynamic Programming', 'Recursion', 'C++'] | 4 |
longest-unequal-adjacent-groups-subsequence-ii | Video Explanation (Brute force to DP) | video-explanation-brute-force-to-dp-by-c-w3nt | Explanation\n\nClick here for the video\n\n# Code\n\nclass Solution {\n\n vector<vector<int>> possible_nxt;\n vector<int> dp;\n vector<int> best_nxt;\n | codingmohan | NORMAL | 2023-10-14T17:17:21.143386+00:00 | 2023-10-14T17:17:21.143408+00:00 | 239 | false | # Explanation\n\n[Click here for the video](https://youtu.be/xhIg9JNUgjA)\n\n# Code\n```\nclass Solution {\n\n vector<vector<int>> possible_nxt;\n vector<int> dp;\n vector<int> best_nxt;\n int n; \n\n int LongestSubsequence (int ind) {\n if (ind == n) return 0;\n \n int& ans = dp[... | 10 | 0 | ['C++'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | [Python 3] Top-Down DP | python-3-top-down-dp-by-abhishek_nub-vius | \nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n @lru_cache(None)\n | abhishek_nub | NORMAL | 2023-10-14T16:08:49.686931+00:00 | 2023-10-14T16:09:05.670889+00:00 | 575 | false | ```\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n @lru_cache(None)\n def dp(i):\n pik = []\n \n for j in range(i, n):\n if groups[i] != groups[j] and len(words[i]) == len(w... | 9 | 0 | ['Dynamic Programming', 'Python', 'Python3'] | 4 |
longest-unequal-adjacent-groups-subsequence-ii | 😎C++ ||✅ Easy to Understand ||✅ Dynamic Programming ||✅ LIS Variants ||✅ Parent marking | c-easy-to-understand-dynamic-programming-irfp | ----------------------------------------------------------------------\n# Please Do upvote if you like this solution\n------------------------------------------ | mannchandarana | NORMAL | 2023-10-14T18:13:10.767232+00:00 | 2023-10-14T18:13:10.767266+00:00 | 406 | false | ----------------------------------------------------------------------\n# Please Do upvote if you like this solution\n----------------------------------------------------------------------\n# Let\'s Connect on :- [LinkedIn](https://www.linkedin.com/in/mann-chandarana-115255230/)\n---------------------------------------... | 6 | 1 | ['Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Directed Graph + DFS | directed-graph-dfs-by-aman_8055-2g6v | Intuition\nConstruct a directed graph connecting indices that meet the described criteria.\nThis graph may not be fully connected but will always be acyclic.Nex | aman_8055 | NORMAL | 2023-10-14T16:01:40.496050+00:00 | 2023-10-14T16:02:51.829438+00:00 | 291 | false | # Intuition\nConstruct a directed graph connecting indices that meet the described criteria.\nThis graph may not be fully connected but will always be acyclic.Next, from the root of each connected component, we must find a path to the deepest node.\nMaintain a global list to record the longest solution for each compone... | 5 | 0 | ['C++'] | 2 |
longest-unequal-adjacent-groups-subsequence-ii | 🎨 The ART of Dynamic Programming | the-art-of-dynamic-programming-by-clayto-povv | \uD83C\uDFA8 The ART of Dynamic Programming: similar to Kadane\'s algorithm, let dp[i] denote the "best path ending here" at each ith index, initialized with ea | claytonjwong | NORMAL | 2023-10-18T21:56:53.375145+00:00 | 2023-11-10T01:25:16.992625+00:00 | 114 | false | [\uD83C\uDFA8 The ART of Dynamic Programming:](https://leetcode.com/discuss/general-discussion/712010/The-ART-of-Dynamic-Programming-An-Intuitive-Approach%3A-from-Apprentice-to-Master) similar to Kadane\'s algorithm, let `dp[i]` denote the *"best path ending here"* at each `i`<sup>th</sup> index, initialized with each ... | 4 | 0 | [] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ || ✅🧭Beats 90 % || LIS variation + Parent marking | c-beats-90-lis-variation-parent-marking-9ihdj | Intuition\nWording of problem was that in subsequence, for the consecutive element, groups[j] != groups[j+1] and match the size of words + hamming distance == 1 | Monstid | NORMAL | 2023-10-14T16:06:32.259823+00:00 | 2023-10-14T16:17:57.740773+00:00 | 692 | false | # Intuition\nWording of problem was that in subsequence, for the consecutive element, groups[j] != groups[j+1] and match the size of words + hamming distance == 1\n\nDo the normal LIS + parent array to backtrack the resulting array of strings\n\nIt would be great to understand with a visual cue, take help of example\n<... | 3 | 0 | ['Dynamic Programming', 'Backtracking', 'C++'] | 3 |
longest-unequal-adjacent-groups-subsequence-ii | LIS Solution | lis-solution-by-tlecodes-dxga | 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 | tlecodes | NORMAL | 2024-10-10T15:31:15.609654+00:00 | 2024-10-10T15:31:15.609684+00:00 | 22 | false | # 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 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Java DP solution beats 95% with detailed explanation | java-dp-solution-beats-95-with-detailed-wu5qo | \n# Approach\n Describe your approach to solving the problem. \nWe use dynamic programming to solve this problem. We have a check array and each index represent | kevinyyh | NORMAL | 2023-10-24T08:25:57.637037+00:00 | 2023-10-24T08:25:57.637054+00:00 | 80 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe use dynamic programming to solve this problem. We have a ```check``` array and each index represents the longest subsequence up til this index and this index is included in this longest subsequence. For every element in ```words```, we check all ... | 2 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [C++] Dynamic Programmin with the longest subsequence indices | c-dynamic-programmin-with-the-longest-su-tbjv | Intuition\n Describe your first thoughts on how to solve this problem. \nFor each words[i], we can append or not append it to a subsequence ended with words[j], | pepe-the-frog | NORMAL | 2023-10-18T12:54:28.086765+00:00 | 2023-10-18T12:54:28.086790+00:00 | 491 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each `words[i]`, we can append or not append it to a subsequence ended with `words[j], where j = [0, i)`(if `words[i]` and `words[j]` meet the conditions)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- `dp[i... | 2 | 0 | ['Array', 'String', 'Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | ✅🔥 Java Easy Solution ✅🔥 | java-easy-solution-by-vishesht27-9t4h | Intuition\nThe problem requires us to find the longest subsequence of words such that the conditions regarding group inequality and hamming distance are satisfi | vishesht27 | NORMAL | 2023-10-16T05:25:54.758899+00:00 | 2023-10-16T05:25:54.758927+00:00 | 87 | false | # Intuition\nThe problem requires us to find the longest subsequence of words such that the conditions regarding group inequality and hamming distance are satisfied. One way to approach this is to make a decision at every index: either to include the current word in our subsequence or skip it. This gives us a hint that... | 2 | 0 | ['Array', 'Hash Table', 'Math', 'String', 'Recursion', 'Memoization', 'Hash Function', 'Java'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | Beats 100%(63ms) || C++ || Dynamic Programming | beats-10063ms-c-dynamic-programming-by-h-di73 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. \n\n\n\n\n\n\n\n\n \n\n# Code\n\nclass Solution {\npublic:\n bool ham(string & | Harshal_Holkar | NORMAL | 2023-10-15T14:10:01.780886+00:00 | 2023-10-15T14:10:01.780918+00:00 | 75 | false | <!-- # 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:\nAdd your space c... | 2 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LIS approach | O(N^2) solution | Java | lis-approach-on2-solution-java-by-bishal-7pv0 | Intuition\n Describe your first thoughts on how to solve this problem. \nThis problem is a slight variation of the famous LIS (Longest Increasing Subsequence) p | bishalkundu17 | NORMAL | 2023-10-14T16:52:02.287684+00:00 | 2023-10-14T16:59:12.142763+00:00 | 156 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is a slight variation of the famous LIS (Longest Increasing Subsequence) problem.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn LIS we used to store the length of the LIS starting from index 0 ...... | 2 | 0 | ['Dynamic Programming', 'Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LSI VARIANT TOP DOWN DP | lsi-variant-top-down-dp-by-sai_govind_20-bsre | \n\nclass Solution {\n List<String> longestSubsequence = new ArrayList<>();\n Map<String, List<String>> memo = new HashMap<>();\n\n boolean isHammingDi | Sai_Govind_2024 | NORMAL | 2023-10-14T16:09:44.868057+00:00 | 2023-10-19T17:03:48.996741+00:00 | 268 | false | ```\n\nclass Solution {\n List<String> longestSubsequence = new ArrayList<>();\n Map<String, List<String>> memo = new HashMap<>();\n\n boolean isHammingDistanceOne(String str1, String str2) {\n if (str1.length() != str2.length()) {\n return false;\n }\n int diffCount = 0;\n ... | 2 | 0 | ['Dynamic Programming', 'Memoization', 'Java'] | 2 |
longest-unequal-adjacent-groups-subsequence-ii | LIS DP solution | lis-dp-solution-by-ujjwal-zmyd | Intuition\nWe can relate this problem to the longest increasing subsequence as we have to find the longest subsequence with a given condition which needs to be | ujjwal___ | NORMAL | 2023-10-14T16:02:21.613579+00:00 | 2023-10-14T16:02:21.613607+00:00 | 239 | false | # Intuition\nWe can relate this problem to the longest increasing subsequence as we have to find the longest subsequence with a given condition which needs to be checked before considering it to subsequence. In LIS it\'s current number should be greater than previous and here it is that groups should be different from ... | 2 | 1 | ['C++'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | Intuition | Optimized Solution | With Universal LIS template | intuition-optimized-solution-with-univer-z7mz | IntuitionThe question demands length of longest increasing subsequence based on certain condition, hence it is a LIS variantApproachBelow is Universal Template | RadhaKrishnaaaa | NORMAL | 2025-01-04T01:23:16.312851+00:00 | 2025-01-04T01:26:16.754676+00:00 | 48 | false | # Intuition
The question demands length of longest increasing subsequence based on certain condition, hence it is a LIS variant
# Approach
**Below is Universal Template for all LIS questions**:
*NOTE: IT IS LIS VARIANT*
1) ***How to idetify LIS variant?***
Any question which asks for longest subsequence based on ce... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DFS Python solution | dfs-python-solution-by-programcoder99-pvai | Intuition\nBased on the same DFS solution given here in C++, but this is a Python3 version\n\n# Approach\nDo a DFS walk from each node that has not been visited | ProgramCoder99 | NORMAL | 2023-11-03T16:59:12.686800+00:00 | 2023-11-03T16:59:12.686824+00:00 | 37 | false | # Intuition\nBased on the same DFS solution given here in C++, but this is a Python3 version\n\n# Approach\nDo a DFS walk from each node that has not been visited yet. At each step if the adjacent node is visited and its level `visit_level` is GTE to the current node, stop further exploration. This is because it means ... | 1 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Straightforward Python DP Solution | straightforward-python-dp-solution-by-se-ipbb | 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 | sekerez | NORMAL | 2023-10-17T04:11:54.992439+00:00 | 2023-10-17T04:11:54.992464+00:00 | 27 | false | # 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: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity ... | 1 | 0 | ['Python3'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | Fastest Python Solution (Faster than 100 %) with graph and DP solution | fastest-python-solution-faster-than-100-4way9 | Intuition\n Describe your first thoughts on how to solve this problem. \nJust a small request i.e don\'t look the length of solution and just go away once see m | praneeth_nellut1 | NORMAL | 2023-10-15T17:23:55.645874+00:00 | 2023-10-15T17:23:55.645898+00:00 | 38 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust a small request i.e don\'t look the length of solution and just go away once see my intution and see each and every code snippet as a block then you will also get my approch.\n\nThe basic intution behind this solution is given in pro... | 1 | 0 | ['Dynamic Programming', 'Depth-First Search', 'Graph', 'Recursion', 'Memoization', 'Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [Python 3] 15x speedup over the current fastest solutions (0.115 ms vs 1.728 s) | python-3-15x-speedup-over-the-current-fa-rb8e | Intuition\nThe graph is a DAG, after building the graph you can use DP to compute the longest path.\n\n# Approach\nAfter building the graph you can traverse the | nan-do | NORMAL | 2023-10-15T13:26:46.818688+00:00 | 2023-10-15T13:34:42.797395+00:00 | 54 | false | # Intuition\nThe graph is a DAG, after building the graph you can use DP to compute the longest path.\n\n# Approach\nAfter building the graph you can traverse the graph from the highest to the lowest index caching the intermediate results, having a couple of auxiliary arrays to keep track of the succesor and the length... | 1 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [Python] ✅ Easy beginner solution - O(n^2) || Beats 100% | python-easy-beginner-solution-on2-beats-ecbc2 | \n\n\n## Explanation\n Describe your approach to solving the problem. \nStep 1. Precompute the hamming distance between any two words and store the precomputed | lshamsschaal | NORMAL | 2023-10-14T22:59:55.919964+00:00 | 2023-10-17T05:03:53.185417+00:00 | 180 | false | \n\n\n## Explanation\n<!-- Describe your approach to solving the problem. -->\nStep 1. Precompute the hamming distance between any two words and store the precomputed distances... | 1 | 0 | ['Dynamic Programming', 'Python3'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | simple LIS Solution | simple-lis-solution-by-priyanshucoding-8wje | \n\nclass Solution {\npublic:\n \n \n int get(string s,string t){\n if(s.size()!=t.size()) return 2;\n \n int ct=0;\n for(i | priyanshucoding | NORMAL | 2023-10-14T18:15:56.063055+00:00 | 2023-10-14T18:15:56.063074+00:00 | 141 | false | ```\n\nclass Solution {\npublic:\n \n \n int get(string s,string t){\n if(s.size()!=t.size()) return 2;\n \n int ct=0;\n for(int i=0;i<s.size();i++){\n if(s[i]!=t[i]) ct++;\n }\n \n if(ct!=1) return 2;\n return 1;\n }\n \n vector<strin... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy solution || C++ || DP | easy-solution-c-dp-by-ankit6378yadav-wj1o | Code\n\nclass Solution {\npublic:\n bool cmp(string a, string b){\n if(a.size()!=b.size()) return false;\n int cnt=0;\n for(int i=0;i<a. | ankit6378yadav | NORMAL | 2023-10-14T17:13:43.721801+00:00 | 2023-10-14T17:13:43.721825+00:00 | 272 | false | # Code\n```\nclass Solution {\npublic:\n bool cmp(string a, string b){\n if(a.size()!=b.size()) return false;\n int cnt=0;\n for(int i=0;i<a.size();i++){\n if(a[i]!=b[i]){\n cnt++;\n if(cnt>1) return false;\n }\n }\n return cnt==1... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ || LIS || Standard DP || | c-lis-standard-dp-by-neon772-glt9 | 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 | neon772 | NORMAL | 2023-10-14T17:02:42.402012+00:00 | 2023-10-14T17:02:42.402038+00:00 | 37 | false | # 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 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [Python] Bottom-up, LIS, Process string length separately | python-bottom-up-lis-process-string-leng-6qck | Approach\n- Handle each string length separately\n- Return the maximum of the longest subsequence for each length\n- Use a parents array to get the subsequence | liivan256 | NORMAL | 2023-10-14T16:44:02.012062+00:00 | 2023-10-14T16:44:02.012085+00:00 | 19 | false | # Approach\n- Handle each string length separately\n- Return the maximum of the longest subsequence for each length\n- Use a parents array to get the subsequence (otherwise we only have the length)\n\n# Complexity\n- Time complexity: $$O(n^2)$$\nWorst case is when all strings have equal length.\n\n- Space complexity: $... | 1 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LIS variation 💉 | Brute force 😱 | Easy to implement 💯 | lis-variation-brute-force-easy-to-implem-d3d0 | Code\n\nclass Solution {\npublic:\n bool hamming_distance_1(string &s, string &t) {\n int c=0;\n if((s.size()!=t.size()) || (s==t)) return 0;\n | naveen-chokkapu | NORMAL | 2023-10-14T16:33:03.196132+00:00 | 2023-10-14T16:52:02.620129+00:00 | 94 | false | # Code\n```\nclass Solution {\npublic:\n bool hamming_distance_1(string &s, string &t) {\n int c=0;\n if((s.size()!=t.size()) || (s==t)) return 0;\n for(int i=0;i<s.size();i++) {\n if(s[i]!=t[i]) c++;\n if(c>1) return 0;\n }\n return c==1;\n }\n vector<s... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [JAVA] Bottom Up DP O(n^2) Simple, 41ms | java-bottom-up-dp-on2-simple-41ms-by-frv-dde2 | Problem 3 of the Biweekly Contest 115\n# Intuition\n Describe your first thoughts on how to solve this problem. \nDP is commonly used in subsequence problems so | frvnk | NORMAL | 2023-10-14T16:21:32.318084+00:00 | 2023-10-14T19:02:19.657888+00:00 | 118 | false | Problem 3 of the Biweekly Contest 115\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDP is commonly used in subsequence problems so I went with that. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe want to have a DP array where DP[i] stores the length of the... | 1 | 0 | ['Dynamic Programming', 'Java'] | 1 |
longest-unequal-adjacent-groups-subsequence-ii | Dynamic Programming || Easy to understand || C++ | dynamic-programming-easy-to-understand-c-vtno | \n# Complexity\n- Time complexity : O(n^2)\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) | GojoSatrou | NORMAL | 2023-10-14T16:19:39.803380+00:00 | 2023-10-14T16:19:39.803398+00:00 | 125 | false | \n# Complexity\n- Time complexity : $$O(n^2)$$\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```\nclass Solution {\npublic:\n // This function finds the longest subsequence of words with specific conditions... | 1 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy C++ DP Solution || Explain Intuition | easy-c-dp-solution-explain-intuition-by-0k4kn | \n# Code\n\nclass Solution {\npublic:\n \n vector<int> dp;\n vector<string> getWordsInLongestSubsequence(int n, vector<string>& words, vector<int>& gro | manraj_singh_16447 | NORMAL | 2023-10-14T16:13:16.317974+00:00 | 2023-10-14T16:13:16.318007+00:00 | 212 | false | \n# Code\n```\nclass Solution {\npublic:\n \n vector<int> dp;\n vector<string> getWordsInLongestSubsequence(int n, vector<string>& words, vector<int>& groups) {\n \n dp.resize(n , -1);\n \n \n int maxi = 0 , index = 0;\n \n // keeping next stored of each indx to ... | 1 | 1 | ['Dynamic Programming', 'Memoization', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | [JAVA] 100% Faster | O(n^2) Time | Dynamic Programming | Longest Increasing Subsequence Pattern | | java-100-faster-on2-time-dynamic-program-r569 | Please Upvote if you understand the approach.\n\n# Complexity\n- Time complexity: O(n^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n) | yash_vish87 | NORMAL | 2023-10-14T16:02:59.926832+00:00 | 2023-10-14T16:20:44.029732+00:00 | 215 | false | # Please Upvote if you understand the approach.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\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```\nclass Solution {\n private boolean validHamming(String word1, S... | 1 | 1 | ['Dynamic Programming', 'Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | simple intuitive dp similar to lcs/lis pattern | simple-intuitive-dp-similar-to-lcslis-pa-cqvm | \nclass Solution {\npublic:\n int dis(string &a, string&b)\n {\n if(a.size()!=b.size()) return false;\n int n=a.size();\n int c=0;\n | demon_code | NORMAL | 2023-10-14T16:01:59.448215+00:00 | 2023-10-14T16:12:22.347066+00:00 | 157 | false | ```\nclass Solution {\npublic:\n int dis(string &a, string&b)\n {\n if(a.size()!=b.size()) return false;\n int n=a.size();\n int c=0;\n for(int i=0; i<n; i++) if(a[i]!=b[i]) c++;\n \n return c==1;\n \n }\n \n vector<string> getWordsInLongestSubsequence(int... | 1 | 0 | ['C'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LIS VARIANT | USE SIMPLE LIS TEMPLATE | lis-variant-use-simple-lis-template-by-h-rt9o | IntuitionThis questions revolves arouund lisApproachCheck the condition as described in the question .
Similar to LIS , we run two loops i and j i from 1 to n a | Harshthakur1079 | NORMAL | 2025-04-11T11:24:58.381157+00:00 | 2025-04-11T11:24:58.381157+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
This questions revolves arouund lis
# Approach
<!-- Describe your approach to solving the problem. -->
Check the condition as described in the question .
Similar to LIS , we run two loops i and j i from 1 to n and j from 0 to less than i ... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Longest Hamming Distance Subsequence with Different Groups | longest-hamming-distance-subsequence-wit-u3rk | IntuitionWe need to find the longest subsequence of words such that:
Each consecutive pair of words in the subsequence has a Hamming distance of exactly 1 (only | kuldeepchaudhary123 | NORMAL | 2025-03-19T12:27:41.775347+00:00 | 2025-03-19T12:27:41.775347+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to find the longest subsequence of words such that:
1. Each consecutive pair of words in the subsequence has a Hamming distance of exactly 1 (only one character difference).
2. The words in the subsequence must belong to different ... | 0 | 0 | ['Array', 'String', 'Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DP | dp-by-linda2024-uax5 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2025-03-06T23:11:27.058720+00:00 | 2025-03-06T23:11:27.058720+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C#'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | beats Minimum 90 || readable code | beats-minimum-90-readable-code-by-sumant-vzc5 | Code | sumanth2328 | NORMAL | 2025-02-23T23:08:08.378447+00:00 | 2025-02-23T23:08:08.378447+00:00 | 2 | false |
# Code
```python3 []
class Solution:
def getWordsInLongestSubsequence(self, words: List[str], groups: List[int]) -> List[str]:
dp=[1]*len(words)
mem=[-1]*len(words)
for i in range(len(words)-1,-1,-1):
for j in range(i+1,len(words)):
if groups[i]!=groups[j] and le... | 0 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | longest inc subsequence variant || optimized code | longest-inc-subsequence-variant-optimize-8gnt | Code | sumanth2328 | NORMAL | 2025-02-07T15:30:40.720191+00:00 | 2025-02-07T15:30:40.720191+00:00 | 6 | false |
# Code
```python3 []
class Solution:
def getWordsInLongestSubsequence(self, words: List[str], groups: List[int]) -> List[str]:
dp=[1]*(len(words))
store=[-1]*len(words)
for i in range(len(words)-1,-1,-1):
for j in range(i+1,len(words)):
hammingdistance = 0
... | 0 | 0 | ['Array', 'String', 'Dynamic Programming', 'Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | scala threeliner | scala-threeliner-by-vititov-8w0z | null | vititov | NORMAL | 2025-02-06T10:39:09.819185+00:00 | 2025-02-06T10:39:09.819185+00:00 | 1 | false | ```scala []
object Solution {
import scala.util.chaining._
def getWordsInLongestSubsequence(words: Array[String], groups: Array[Int]): List[String] = {
lazy val aMap = (for{
i <- words.indices.to(List)
j <- Iterator.range(i+1,words.length)
if words(i).size == words(j).size && groups(i) != grou... | 0 | 0 | ['Dynamic Programming', 'Greedy', 'Scala'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DP solution JAVA | dp-solution-java-by-prachikumari-d3y9 | IntuitionNot much of complex dp :
Things to keep in mind :
Get the maxSubLen (following all conditions) ending at any index i
Take the maxSubLen, and retrace th | PrachiKumari | NORMAL | 2025-01-15T13:31:30.129101+00:00 | 2025-01-15T13:31:30.129101+00:00 | 3 | false | # Intuition
Not much of complex dp :
Things to keep in mind :
- Get the maxSubLen (following all conditions) ending at any index i
- Take the maxSubLen, and retrace the index of words making the subsequence ending at ith index (longest length)
- To retrace the path for resultant list of strings, keep tracking the prev ... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Bottom-up DP, beats 100% | bottom-up-dp-beats-100-by-germanov_dev-a0p7 | Complexity
Time complexity:
O(n2)
Space complexity:
O(n2)
Code | germanov_dev | NORMAL | 2025-01-11T12:11:04.125217+00:00 | 2025-01-11T12:11:04.125217+00:00 | 4 | false | # Complexity
- Time complexity:
$$O(n^2)$$
- Space complexity:
$$O(n^2)$$
# Code
```rust []
impl Solution {
pub fn get_words_in_longest_subsequence(words: Vec<String>, groups: Vec<i32>) -> Vec<String> {
let mut dp:Vec<Vec<&str>> = vec![vec![];words.len()];
dp[words.len()-1] = vec![];
let (... | 0 | 0 | ['Rust'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Deep Down DP lane | deep-down-dp-lane-by-tonitannoury01-2lxd | IntuitionApproachComplexity
Time complexity:
O(n**2)
Space complexity:
O(n)
Code | tonitannoury01 | NORMAL | 2024-12-26T20:15:51.583193+00:00 | 2024-12-26T20:15:51.583193+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(n**2)
- Space complexity:
O(n)
# Code
```javascript []
/**
* @param {string[]} words
* @param {number[]} groups
* @return {string[]}... | 0 | 0 | ['JavaScript'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy Graph+DFS | easy-graphdfs-by-arcanex-05zr | Intuition
Initial Realization: Need to find longest valid chain of words. Reminds of longest path problem.
Key Insight: We can model this as a graph where: | arcanex | NORMAL | 2024-12-21T10:20:18.016298+00:00 | 2024-12-21T10:20:18.016298+00:00 | 6 | false | # Intuition
- Initial Realization: Need to find longest valid chain of words. Reminds of longest path problem.
- Key Insight: We can model this as a graph where:
- Nodes = words
- Edge exists if words have:
- Same length
- Hamming distance ≤ 1
- Different groups
- This transforms probl... | 0 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Python consice 6-line DP | python-consice-6-line-dp-by-dsapelnikov-vd4w | Approach\nThe DP pattern is similar to the one in the longest increasing subsequence. But we collect actual words instead of subsequence lengths.\n\n# Complexit | dsapelnikov | NORMAL | 2024-11-13T10:12:52.540927+00:00 | 2024-11-13T10:14:20.248813+00:00 | 4 | false | # Approach\nThe DP pattern is similar to the one in the longest increasing subsequence. But we collect actual words instead of subsequence lengths.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n- Space complexity: $$O(n^2)$$\n\n# Code\n```python3 []\nclass Solution:\n def getWordsInLongestSubsequence(self, words: ... | 0 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ O(n*n), dp | c-onn-dp-by-cx3129-0dqu | 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 | cx3129 | NORMAL | 2024-09-24T01:28:23.874524+00:00 | 2024-09-24T01:28:56.572205+00:00 | 4 | false | # 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)$$ -->\nO(n*n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DP | dp-by-abdelrahman-adel7-9905 | \npublic class Solution {\n List<string> result = new();\n int[,] dp = null;\n\n public IList<string> GetWordsInLongestSubsequence(string[] words, int[ | Abdelrahman-Adel7 | NORMAL | 2024-09-07T00:57:10.519295+00:00 | 2024-09-07T00:57:10.519320+00:00 | 0 | false | ```\npublic class Solution {\n List<string> result = new();\n int[,] dp = null;\n\n public IList<string> GetWordsInLongestSubsequence(string[] words, int[] groups)\n {\n dp = new int[words.Length + 1, words.Length + 1];\n for (int j = 0; j <= groups.Length; j++)\n {\n for (in... | 0 | 0 | [] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy Iterative Dp Solution | easy-iterative-dp-solution-by-kvivekcode-mynz | 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 | kvivekcodes | NORMAL | 2024-08-29T04:06:48.758540+00:00 | 2024-08-29T04:06:48.758566+00:00 | 1 | false | # 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)$$ --... | 0 | 0 | ['Array', 'String', 'Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | c++ beginner friendly dp | c-beginner-friendly-dp-by-pb_matrix-wdfw | \nclass Solution {\npublic:\n bool fn(vector<string>&v,int i,int j){\n string s1=v[i],s2=v[j];\n int ans=0;\n for(int k=0;k<s1.size();k+ | pb_matrix | NORMAL | 2024-08-28T11:42:20.013030+00:00 | 2024-08-28T11:42:20.013055+00:00 | 0 | false | ```\nclass Solution {\npublic:\n bool fn(vector<string>&v,int i,int j){\n string s1=v[i],s2=v[j];\n int ans=0;\n for(int k=0;k<s1.size();k++) ans+=(s1[k]!=s2[k]);\n return s1.size()==s2.size() && ans==1;\n }\n vector<string> getWordsInLongestSubsequence(vector<string>&v,vector<int>&... | 0 | 0 | ['Dynamic Programming', 'C'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Current Fastest C# Solution - Dynamic Programming | current-fastest-c-solution-dynamic-progr-jmmo | Intuition\nFor each word, find all subsequences it can connect to, then connect the word to the longest out of all candidate subsequences. The returned value wi | theuncleofalex | NORMAL | 2024-08-03T19:38:14.522961+00:00 | 2024-08-03T19:38:14.522993+00:00 | 0 | false | # Intuition\nFor each word, find all subsequences it can connect to, then connect the word to the longest out of all candidate subsequences. The returned value will be the longest subsequence.\n\n# Approach\nCreate an array of backpointers representing each node\'s connected subsequence. Also create an array of lengths... | 0 | 0 | ['C#'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Simple C++ Solution | DP | Tabulation | simple-c-solution-dp-tabulation-by-rj_99-gsn5 | 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 | rj_9999 | NORMAL | 2024-07-06T09:52:23.420779+00:00 | 2024-07-06T09:52:23.420815+00:00 | 14 | false | # 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)$$ --... | 0 | 0 | ['Array', 'String', 'Dynamic Programming', 'Memoization', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | JAVA SOLUTION | java-solution-by-danish_jamil-mkyf | Intuition\n\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- Tim | Danish_Jamil | NORMAL | 2024-06-29T06:10:20.770860+00:00 | 2024-06-29T06:10:20.770890+00:00 | 8 | false | # Intuition\n\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 you... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ | DP | LIS | c-dp-lis-by-mrchromatic-t0he | Code\n\nclass Solution {\npublic:\n int hamming_distance(string s1,string s2){\n int ct=0;\n for(int i=0;i<s1.size();i++){\n if(s1[i | MrChromatic | NORMAL | 2024-06-26T12:34:18.863663+00:00 | 2024-06-26T12:34:18.863697+00:00 | 5 | false | # Code\n```\nclass Solution {\npublic:\n int hamming_distance(string s1,string s2){\n int ct=0;\n for(int i=0;i<s1.size();i++){\n if(s1[i]!=s2[i])\n ct++;\n if(ct==2)\n return 2;\n }\n return ct;\n }\n vector<string> getWordsInLong... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | USING C++ || LIS EASY KEEP PAR OF EACH INDEX | using-c-lis-easy-keep-par-of-each-index-znzpb | 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 | hmaan | NORMAL | 2024-06-05T12:17:47.942058+00:00 | 2024-06-05T12:17:47.942092+00:00 | 4 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LIS Bottom-up solution | lis-bottom-up-solution-by-deshmukhrao-hnuu | 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 | DeshmukhRao | NORMAL | 2024-05-30T13:09:18.937061+00:00 | 2024-05-30T13:09:18.937091+00:00 | 3 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Longest Unequal Adjacent Groups Subsequence - ii || JavaScript || 100% Beats | longest-unequal-adjacent-groups-subseque-b3iw | Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve the problem of finding the longest subsequence of words where each word is in | user4609eh | NORMAL | 2024-05-18T12:40:53.469591+00:00 | 2024-05-18T12:40:53.469622+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve the problem of finding the longest subsequence of words where each word is in a different group and the Hamming distance between consecutive words in the subsequence is exactly 1, we can use dynamic programming. The idea is to bu... | 0 | 0 | ['JavaScript'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Can anyone help to solve my confusion? Thank you very much | can-anyone-help-to-solve-my-confusion-th-e2hj | The question states that "For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij+1], for each j where 0 | adamchen564 | NORMAL | 2024-05-04T15:16:36.279370+00:00 | 2024-05-04T15:19:45.318380+00:00 | 28 | false | The question states that "For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij+1], for each j where 0 < j + 1 < k.", my understanding is that the solution subsequences\' groups can be \'1,2,3,1,2,3\', but many of the solutions that I have seen (that pass all tes... | 0 | 0 | ['Swift', 'C', 'Python', 'Java', 'Go', 'Python3', 'Ruby', 'JavaScript', 'C#', 'Bash'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | c++ solution | c-solution-by-dilipsuthar60-66uz | \nclass Solution {\npublic:\n bool hammingDistance(string&s1,string&s2)\n {\n if(s1.size()!=s2.size()) return false;\n int count=0;\n | dilipsuthar17 | NORMAL | 2024-04-29T17:27:24.107743+00:00 | 2024-04-29T17:27:24.107776+00:00 | 1 | false | ```\nclass Solution {\npublic:\n bool hammingDistance(string&s1,string&s2)\n {\n if(s1.size()!=s2.size()) return false;\n int count=0;\n for(int i=0;i<s1.size();i++)\n {\n if(s1[i]!=s2[i]) count++;\n if(count>1) return false;\n }\n return true;\n ... | 0 | 0 | ['Dynamic Programming', 'C', 'C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Python (Simple DP) | python-simple-dp-by-rnotappl-x1kr | 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 | rnotappl | NORMAL | 2024-04-09T15:58:55.982399+00:00 | 2024-04-09T15:58:55.982457+00:00 | 9 | false | # 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)$$ --... | 0 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Beats 100.00% of users with Java | beats-10000-of-users-with-java-by-raheel-7hok | 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 | raheels | NORMAL | 2024-04-09T09:13:14.757268+00:00 | 2024-04-09T09:13:14.757292+00:00 | 2 | false | # 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)$$ --... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | O(N^2) LIS DP with Erlang | on2-lis-dp-with-erlang-by-metaphysicalis-f1gw | Approach\n Describe your approach to solving the problem. \nThis problem can be easily solved with the straightforward $O(N^2)$ algorithm for finding the longes | metaphysicalist | NORMAL | 2024-03-23T09:30:09.111665+00:00 | 2024-03-23T09:30:09.111701+00:00 | 4 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nThis problem can be easily solved with the straightforward $O(N^2)$ algorithm for finding the longest increasing subsequence. I solve this problem in Erlang with recursion for finding the solution as well. No additional backtracking is required to con... | 0 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Erlang'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ | c-by-ayush_gupta4-is03 | 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 | ayush_gupta4 | NORMAL | 2024-03-19T12:41:55.191283+00:00 | 2024-03-19T12:41:55.191314+00:00 | 5 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++/Python, dynamic programming solution with explanation | cpython-dynamic-programming-solution-wit-t82f | dp[i][0] is the max length of sequence whose last element is words[i].\ndp[i][1] is the second to last element of the maximum length sequence, the last one is w | shun6096tw | NORMAL | 2024-03-13T08:06:24.088668+00:00 | 2024-03-13T08:07:35.709685+00:00 | 7 | false | dp[i][0] is the max length of sequence whose last element is words[i].\ndp[i][1] is the second to last element of the maximum length sequence, the last one is words[i].\n\nfor each j in [0, i-1],\nif words[j] and words[i]\'s distance is 1 and both length are the same and dp[j][0] + 1 > dp[i][0],\ndp[i] = (dp[j][0] + 1,... | 0 | 0 | ['Dynamic Programming', 'C', 'Python'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DP + Backtrack | dp-backtrack-by-cuiyong_cn-wfkt | Intuition\nCode explains better than words.\n\n# Code\n\nauto ham_dist(string const& s1, string const& s2)\n{\n if (s1.length() != s2.length()) {\n re | cuiyong_cn | NORMAL | 2024-03-02T05:54:42.813235+00:00 | 2024-03-02T05:54:42.813262+00:00 | 5 | false | # Intuition\nCode explains better than words.\n\n# Code\n```\nauto ham_dist(string const& s1, string const& s2)\n{\n if (s1.length() != s2.length()) {\n return -1;\n }\n\n int const n = s1.length();\n auto cnt = 0;\n\n for (auto i = 0; i < n; ++i) {\n if (s1[i] != s2[i]) {\n ++cn... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | 🔥Java Solution || Dp (Concept : LIS) | java-solution-dp-concept-lis-by-neel_diy-rquw | \n\nclass Solution {\n public List<String> getWordsInLongestSubsequence(String[] words, int[] groups) {\n int n = words.length;\n\n int[] dp = | anjan_diyora | NORMAL | 2024-02-26T16:59:57.171108+00:00 | 2024-02-26T16:59:57.171136+00:00 | 12 | false | \n```\nclass Solution {\n public List<String> getWordsInLongestSubsequence(String[] words, int[] groups) {\n int n = words.length;\n\n int[] dp = new int[n];\n int[] hash = new int[n];\n \n Arrays.fill(dp, 1);\n\n int max = 1;\n int lastIndex = 0;\n for(int curr = ... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | JAVA 100%, Simple Solution using Parent[]/Size[] array | java-100-simple-solution-using-parentsiz-bufv | 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 | meringueee | NORMAL | 2024-02-21T23:57:58.111065+00:00 | 2024-02-21T23:57:58.111106+00:00 | 8 | false | # 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)$$ --... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Tabulation + Tracing | tabulation-tracing-by-piro_coder13-blt6 | Approach\nTabulate the counts for each index when they satisfy the given conditions, then trace back the strings from maximum dp tabulated value.\n\n# Complexit | piro_coder13 | NORMAL | 2024-02-13T21:59:21.934559+00:00 | 2024-02-13T21:59:21.934591+00:00 | 1 | false | # Approach\nTabulate the counts for each index when they satisfy the given conditions, then trace back the strings from maximum dp tabulated value.\n\n# Complexity\n- Time complexity:\nO(N*N*10)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n vector<string> getWordsInLongestSubsequence(int n... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | DP | O(NlogN) | Beats 92.91% of users with Python3 | dp-onlogn-beats-9291-of-users-with-pytho-jjxu | Code\n\nclass Solution:\n def isWordSatisfied(self, word1: str, word2: str, dist=1):\n if len(word2) == len(word1):\n for c1, c2 in zip(wor | timo9madrid7 | NORMAL | 2024-01-26T11:53:09.633095+00:00 | 2024-01-26T11:53:09.633125+00:00 | 18 | false | # Code\n```\nclass Solution:\n def isWordSatisfied(self, word1: str, word2: str, dist=1):\n if len(word2) == len(word1):\n for c1, c2 in zip(word2, word1):\n if c1 == c2:\n continue\n dist -= 1\n if dist < 0:\n retur... | 0 | 0 | ['Python3'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Koltin Easy solution | koltin-easy-solution-by-gideonrotich-nxwr | 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 | gideonrotich | NORMAL | 2024-01-25T18:30:05.376422+00:00 | 2024-01-25T18:30:05.376446+00:00 | 1 | false | # 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)$$ --... | 0 | 0 | ['Kotlin'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy, fast, efficient python solution | easy-fast-efficient-python-solution-by-l-pg6n | Intuition\nDynamic Programming,\nInitialize a table(ans) to store the current longest sequence and the previous word\'s idx;\nUpdate the longest sequence for ea | LouiseLi7 | NORMAL | 2024-01-24T05:28:30.659849+00:00 | 2024-01-24T05:28:30.659891+00:00 | 1 | false | # Intuition\nDynamic Programming,\nInitialize a table(ans) to store the current longest sequence and the previous word\'s idx;\nUpdate the longest sequence for each word if requirements meet (hamming distance ==1, equal length, longer than the word\'s current longest sequence)\nBacktrack the words and append words by i... | 0 | 0 | ['Python'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy, fast, efficient python solution | easy-fast-efficient-python-solution-by-l-xc4l | Intuition\nDynamic Programming,\nInitialize a table(ans) to store the current longest sequence and the previous word\'s idx;\nUpdate the longest sequence for ea | LouiseLi7 | NORMAL | 2024-01-24T05:28:29.392917+00:00 | 2024-01-24T05:28:29.392958+00:00 | 3 | false | # Intuition\nDynamic Programming,\nInitialize a table(ans) to store the current longest sequence and the previous word\'s idx;\nUpdate the longest sequence for each word if requirements meet (hamming distance ==1, equal length, longer than the word\'s current longest sequence)\nBacktrack the words and append words by i... | 0 | 0 | ['Python'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | LIS Approach C++ Solution | lis-approach-c-solution-by-sultania_anku-xnc5 | 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 | Sultania_Ankush | NORMAL | 2024-01-17T05:04:45.548177+00:00 | 2024-01-17T05:04:45.548238+00:00 | 11 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | clean code with clear thought process, O(n^2) | clean-code-with-clear-thought-process-on-tyg0 | condition satisfies when \n1. groups[i] != groups[i+1]\n2. isHammingDistanceByOne \n\nthought process was\nmemo[]\n2. 1. store longest length in each index , m | youngsam | NORMAL | 2024-01-11T12:33:01.057047+00:00 | 2024-01-11T12:33:01.057065+00:00 | 0 | false | condition satisfies when \n1. groups[i] != groups[i+1]\n2. isHammingDistanceByOne \n\nthought process was\nmemo[]\n2. 1. store longest length in each index , memo[i] =3 means [0...i] longest length is 3 \nindicies[]\n2. store previous index that has longest length in each index, \n then from last index, we trave... | 0 | 0 | [] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Easy understandable and readable java solution | easy-understandable-and-readable-java-so-clm9 | 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 | guptalav465 | NORMAL | 2024-01-05T20:44:12.608482+00:00 | 2024-01-05T20:44:12.608506+00:00 | 3 | false | # 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)$$ --... | 0 | 0 | ['Java'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | C++ | Easy to Understand | c-easy-to-understand-by-goku_2022-78ne | 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 | goku_2022 | NORMAL | 2024-01-03T09:52:09.888166+00:00 | 2024-01-03T09:52:09.888187+00:00 | 5 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
longest-unequal-adjacent-groups-subsequence-ii | Bottom-up dp. Print LIS | bottom-up-dp-print-lis-by-vokasik-tlv0 | For reference look at problem #300\n\n\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], nums: List[int]) -> List[str]:\n | vokasik | NORMAL | 2023-12-16T23:39:51.412185+00:00 | 2023-12-16T23:52:17.474067+00:00 | 0 | false | For reference look at problem #300\n\n```\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], nums: List[int]) -> List[str]:\n N = len(nums)\n dp = [1] * N # max LIS ending @ i\n parent = [-1] * N\n max_end = 0\n for cur in range(N):\n for... | 0 | 0 | ['Dynamic Programming', 'Python'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.