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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
falling-squares | :: Kotlin :: Segment Tree Solution | kotlin-segment-tree-solution-by-znxkznxk-vmqt | \n\n# Code\n\nclass Solution {\n fun fallingSquares(positions: Array<IntArray>): List<Int> {\n val posToIdx = HashMap<Double, Int>()\n val pos | znxkznxk1030 | NORMAL | 2024-07-01T04:39:40.371766+00:00 | 2024-07-01T04:39:40.371795+00:00 | 2 | false | \n\n# Code\n```\nclass Solution {\n fun fallingSquares(positions: Array<IntArray>): List<Int> {\n val posToIdx = HashMap<Double, Int>()\n val pos = mutableListOf<Double>()\n\n for (position in positions) {\n pos.add(position[0].toDouble() + 0.1)\n pos.add((position[0] + pos... | 0 | 0 | ['Kotlin'] | 0 |
falling-squares | Lazy Segment tree || with index 1 | lazy-segment-tree-with-index-1-by-wolfes-i55a | 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 | Wolfester | NORMAL | 2024-06-22T11:00:09.173188+00:00 | 2024-06-22T11:00:09.173214+00:00 | 16 | 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(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e... | 0 | 0 | ['C++'] | 0 |
falling-squares | scala SortedMap | scala-sortedmap-by-vititov-k5ee | scala\nobject Solution {\n import collection.immutable.SortedMap\n def fallingSquares(positions: Array[Array[Int]]): List[Int] =\n positions.map(_.toList)\ | vititov | NORMAL | 2024-06-12T21:23:01.314656+00:00 | 2024-06-12T21:23:01.314676+00:00 | 1 | false | ```scala\nobject Solution {\n import collection.immutable.SortedMap\n def fallingSquares(positions: Array[Array[Int]]): List[Int] =\n positions.map(_.toList)\n .foldLeft((List(-1),SortedMap.empty[Int,(Int,Int)])){case ((l,aMap),p) =>\n lazy val y2 = aMap.maxBefore(p.head).filter{case (k,(len,_)) => k+l... | 0 | 0 | ['Ordered Map', 'Scala'] | 0 |
falling-squares | segment tree | segment-tree-by-moyinolorunpa-pcua | 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 | MoyinolorunPA | NORMAL | 2024-06-10T04:54:15.559280+00:00 | 2024-06-10T04:54:15.559327+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 | ['Python'] | 0 |
falling-squares | Java || 5ms 100% || Fast. Use only arrays for compress and fall | java-5ms-100-fast-use-only-arrays-for-co-3wwv | Algorithm:\n1. Gather all of the left and right edge positions for all squares. For each edge position, save: the original x-position, the index into the posit | dudeandcat | NORMAL | 2024-05-16T23:38:45.192095+00:00 | 2024-05-17T00:14:20.583623+00:00 | 28 | false | **Algorithm:**\n1. **Gather** all of the left and right edge positions for all squares. For each edge position, save: the original x-position, the index into the `positions[][]` array for that square, and whether the saved position is a left or right edge of the square.\n2. **Sort** all the saved edge positions, which... | 0 | 0 | ['Java'] | 0 |
falling-squares | Simple TS | simple-ts-by-pailhead-194v | Intuition\nEach square landing should create an edge at some height, between two points that can catch the next square.\n\n# Approach\nKeep a list of edges that | pailhead | NORMAL | 2024-04-11T03:04:20.368648+00:00 | 2024-04-11T03:06:42.447814+00:00 | 6 | false | # Intuition\nEach square landing should create an edge at some height, between two points that can catch the next square.\n\n# Approach\nKeep a list of edges that represent left, right and height. \nFor each of the squares, find all the edges that overlap the bounds of the square. \nFind which edge from those results i... | 0 | 0 | ['TypeScript'] | 0 |
get-equal-substrings-within-budget | [Java/C++/Python] Sliding Window | javacpython-sliding-window-by-lee215-gcq6 | Intuition\nChange the input of string s and t into an array of difference.\nThen it\'s a standard sliding window problem.\n\n\n## Complexity\nTime O(N) for one | lee215 | NORMAL | 2019-09-29T04:01:58.917594+00:00 | 2019-09-29T07:05:53.272274+00:00 | 15,547 | false | ## **Intuition**\nChange the input of string `s` and `t` into an array of difference.\nThen it\'s a standard sliding window problem.\n<br>\n\n## **Complexity**\nTime `O(N)` for one pass\nSpace `O(1)`\n<br>\n\n**Java:**\n```java\n public int equalSubstring(String s, String t, int k) {\n int n = s.length(), i =... | 172 | 8 | [] | 39 |
get-equal-substrings-within-budget | ✅97.44%🔥Easy solution🔥With explanation🔥 | 9744easy-solutionwith-explanation-by-mra-92yz | Intuition\n#### The problem requires finding the longest substring where the cost of converting it from s to t does not exceed maxCost. To achieve this, we can | MrAke | NORMAL | 2024-05-28T00:26:10.462586+00:00 | 2024-05-28T00:26:10.462613+00:00 | 21,595 | false | # Intuition\n#### The problem requires finding the longest substring where the cost of converting it from `s` to `t` does not exceed `maxCost`. To achieve this, we can utilize a sliding window approach to dynamically adjust the size of the substring while ensuring the cost constraint is respected.\n\n----\n\n# Approach... | 105 | 6 | ['String', 'Sliding Window', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#'] | 12 |
get-equal-substrings-within-budget | Java Sliding Window with Clear Explanation | java-sliding-window-with-clear-explanati-prff | Explanation:\n\nThe idea is that you want to convert one character to another in that same position i.e. s[i] to t[i] such that you form the longest contiguous | kkzeng | NORMAL | 2019-09-29T04:26:40.964616+00:00 | 2019-09-29T19:54:27.316251+00:00 | 4,244 | false | **Explanation:**\n\nThe idea is that you want to convert one character to another in that same position i.e. s[i] to t[i] such that you form the longest contiguous converted String.\n\nThere is just one key realization that you must make to solve this problem:\n\nYou need to realize that this problem can be reduced to ... | 57 | 2 | ['Java'] | 14 |
get-equal-substrings-within-budget | 🔥🔥 Diagrammatic Explanation 👁️👁️ | diagrammatic-explanation-by-hi-malik-jc93 | What the question is saying, we have two strings and have maxCost. Keep maxCost in your mind and tell, a big to big s string can be converted to t string. And i | hi-malik | NORMAL | 2024-05-28T00:26:14.570485+00:00 | 2024-05-28T00:26:14.570522+00:00 | 6,256 | false | What the question is saying, we have **two strings** and have **maxCost**. Keep **maxCost** in your mind and tell, a big to big **s** string can be converted to **t** string. And if we converted the whole string, how much will be the cost!\n\nLet\\s undrestand with an example;\n```\nInput: s = "abcd", t = "bcdf", maxCo... | 56 | 1 | ['C', 'Python', 'Java'] | 11 |
get-equal-substrings-within-budget | [C++] Sliding window O(n) & Prefix sum O(nlogn) implementations | c-sliding-window-on-prefix-sum-onlogn-im-fvsa | Observation\nSince we need to find the maximum substring that can be replaced we can actually breakdown this problem to an array of integers that represent the | phoenixdd | NORMAL | 2019-09-29T04:01:45.948903+00:00 | 2019-10-06T20:12:21.145749+00:00 | 3,986 | false | **Observation**\nSince we need to find the maximum substring that can be replaced we can actually breakdown this problem to an array of integers that represent the replacement cost of `s[i]` to `t[i]` and then find the maximum length of continuous integers in that array whose `sum <= maxCost`.\neg:\n`s = "aabcd"`\n`t =... | 51 | 2 | [] | 4 |
get-equal-substrings-within-budget | Sliding window vs Prefix sum+Binary search||0ms beats 100% | sliding-window-vs-prefix-sumbinary-searc-kghm | Intuition\n Describe your first thoughts on how to solve this problem. \nUse sliding window; it\'s a linear solution with O(1) space.\n\n2nd approach uses prefi | anwendeng | NORMAL | 2024-05-28T00:46:15.162432+00:00 | 2024-05-28T02:38:54.012864+00:00 | 4,650 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse sliding window; it\'s a linear solution with O(1) space.\n\n2nd approach uses prefix sum. Note that `cost[l...r]=sum[r+1]-sum[l]` where `sum` is 1-indexed prefix sums.\n\n3rd approach is a revision for the 2nd one, within the inner lo... | 39 | 3 | ['Binary Search', 'Sliding Window', 'Prefix Sum', 'C++'] | 8 |
get-equal-substrings-within-budget | Standard Python moving window (similar problems listed) | standard-python-moving-window-similar-pr-w6iy | Please see and vote for my solutions for these similar problems.\n1208. Get Equal Substrings Within Budget\n3. Longest Substring Without Repeating Characters\n1 | otoc | NORMAL | 2019-09-29T04:12:23.004153+00:00 | 2019-09-29T04:21:47.175296+00:00 | 1,875 | false | Please see and vote for my solutions for these similar problems.\n[1208. Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/discuss/392901/Simple-Python-moving-window)\n[3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-w... | 36 | 0 | [] | 3 |
get-equal-substrings-within-budget | C++/Java Sliding Window O(n) | O(1) | cjava-sliding-window-on-o1-by-votrubac-er3l | Intuition\nInstead of two string, we can imagine an array of the same size with absolute differences. Then, the problem is to find the longest subarray with the | votrubac | NORMAL | 2019-09-29T04:03:48.007478+00:00 | 2019-09-29T05:02:57.349724+00:00 | 2,588 | false | # Intuition\nInstead of two string, we can imagine an array of the same size with absolute differences. Then, the problem is to find the longest subarray with the sum not exceeding ```maxCost```.\n# Sliding Window\nWe can use a sliding window technique when we move right ```i``` pointer and decrease ```maxCost```, and ... | 34 | 1 | [] | 3 |
get-equal-substrings-within-budget | ✅Detailed Explanation🔥2 Approaches🔥🔥Extremely Simple and effective🔥🔥🔥 Beginner-friendly🔥 | detailed-explanation2-approachesextremel-b5xy | \uD83C\uDFAFProblem Explanation:\nYou are given two strings s and t and integer maxCost. You want to return maximum length of substring from s such that you nee | heir-of-god | NORMAL | 2024-05-28T05:42:33.700104+00:00 | 2024-05-28T06:47:41.944540+00:00 | 1,852 | false | # \uD83C\uDFAFProblem Explanation:\nYou are given two strings ```s``` and ```t``` and integer ```maxCost```. You want to return maximum length of substring from ```s``` such that you need up to ```maxCost``` cost to change it.\n- "cost" is absolute ASCII difference between s[i] and t[i]\n- Substring is a contiguous seq... | 26 | 7 | ['String', 'Binary Search', 'C', 'Sliding Window', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 12 |
get-equal-substrings-within-budget | [Java/Python 3] Sliding window space O(1) w/ brief explanation and analysis. | javapython-3-sliding-window-space-o1-w-b-acpl | Maintain a window and keep accumulating the cost on hi end; if the cost is higher than maxCost, then shrink widow by removing element from lo end; \n2. Update t | rock | NORMAL | 2019-09-29T04:02:23.316633+00:00 | 2019-09-30T07:44:48.502713+00:00 | 1,140 | false | 1. Maintain a window and keep accumulating the cost on `hi` end; if the cost is higher than `maxCost`, then shrink widow by removing element from `lo` end; \n2. Update the max window `width` during each iteration.\n\n```\n public int equalSubstring(String s, String t, int maxCost) {\n int width = 0;\n ... | 18 | 2 | [] | 5 |
get-equal-substrings-within-budget | c++ || easiest | c-easiest-by-rajat_gupta-74xf | \nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n\t\n int n=s.size(),arr[n];\n\t\t\n for(int i=0;i<n;i++)\n | rajat_gupta_ | NORMAL | 2021-05-10T18:10:16.673295+00:00 | 2021-05-10T18:10:16.673342+00:00 | 1,083 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n\t\n int n=s.size(),arr[n];\n\t\t\n for(int i=0;i<n;i++)\n arr[i]=abs(s[i]-t[i]);\n \n int cost=0,start=0,maxlen=INT_MIN;\n\t\t\n for(int i=0;i<n;i++){\n cost+=arr[i];\n ... | 13 | 0 | ['C', 'C++'] | 4 |
get-equal-substrings-within-budget | Python || Easy Clean Solution. Sliding Window. | python-easy-clean-solution-sliding-windo-w5ik | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | dilmurat-aliev | NORMAL | 2023-09-07T13:14:56.647787+00:00 | 2023-09-07T13:14:56.647811+00:00 | 605 | false | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n left = ans = curr = 0\n for... | 12 | 0 | ['String', 'Sliding Window', 'Python3'] | 3 |
get-equal-substrings-within-budget | Easy PrefSum + BinarySearch O(NLogN) | easy-prefsum-binarysearch-onlogn-by-upad-gpcc | Intuition\nThe intution came to me when i was solving the question i saw i needed to find a substring sum which leads me to this size or less.\n# Approach\nMade | upadhyayabhi0107 | NORMAL | 2022-12-20T15:09:28.416814+00:00 | 2022-12-20T15:09:28.416851+00:00 | 1,074 | false | # Intuition\nThe intution came to me when i was solving the question i saw i needed to find a substring sum which leads me to this size or less.\n# Approach\nMade a prefix sum to calculate sum/change cost in O(1)\nThen i searched substring of size k which satisfy the value and then if it satisfied i searched for higher... | 12 | 0 | ['Binary Search', 'Prefix Sum', 'C++'] | 3 |
get-equal-substrings-within-budget | Python Solution with explanation | python-solution-with-explanation-by-a_bs-9cx1 | Intuition\n\nThe problem asks us to find the longest substring where we can change characters in the first string (s) to make it equal to the second string (t) | 20250406.A_BS | NORMAL | 2024-05-28T02:36:01.820770+00:00 | 2024-05-28T02:36:01.820790+00:00 | 389 | false | ## Intuition\n\nThe problem asks us to find the longest substring where we can change characters in the first string (s) to make it equal to the second string (t) within a given cost limit (maxCost). We can solve this using a sliding window approach.\n\n## Approach\n\n1. We\'ll use two pointers: `start` and `end`. `sta... | 10 | 0 | ['Python3'] | 2 |
get-equal-substrings-within-budget | ✅Detailed Explanation💯Beats 100%🔥Sliding Window (+Optimised)🔥1 & 2 pass solutions🔥O(n), O(1)🔥 | detailed-explanationbeats-100sliding-win-sf70 | \nSubmission Link\n> Don\'t mind leetcode submission rating too much, its very random.\n\n# \uD83C\uDFAF Problem Explanation:\nWe are given two strings s and t | Saketh3011 | NORMAL | 2024-05-28T02:06:10.187170+00:00 | 2024-05-28T17:50:26.483293+00:00 | 1,756 | false | \n[Submission Link](https://leetcode.com/problems/get-equal-substrings-within-budget/submissions/1269912694?envType=daily-question&envId=2024-05-28)\n> Don\'t mind leetcode submission rating too much, its v... | 10 | 0 | ['String', 'Sliding Window', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 5 |
get-equal-substrings-within-budget | JAVA ( Sliding Window ) | java-sliding-window-by-infox_92-z7mr | class Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n // Convert the problem into a min subarray problem\n int[] di | Infox_92 | NORMAL | 2022-10-25T17:49:14.197105+00:00 | 2022-10-25T17:49:14.197148+00:00 | 583 | false | class Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n // Convert the problem into a min subarray problem\n int[] diff = new int[s.length()];\n for(int i = 0; i < s.length(); ++i) {\n int asciiS = s.charAt(i);\n int asciiT = t.charAt(i);\n ... | 10 | 0 | [] | 1 |
get-equal-substrings-within-budget | C++ Sliding Window (+ Cheat Sheet) | c-sliding-window-cheat-sheet-by-lzl12463-barf | See my latest update in repo LeetCode\n\n## Solution 1. Sliding Window\n\nCheck out "C++ Maximum Sliding Window Cheatsheet Template!".\n\nShrinkable Sliding Win | lzl124631x | NORMAL | 2021-10-19T06:13:57.959135+00:00 | 2021-10-19T06:13:57.959177+00:00 | 3,566 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Sliding Window\n\nCheck out "[C++ Maximum Sliding Window Cheatsheet Template!](https://leetcode.com/problems/frequency-of-the-most-frequent-element/discuss/1175088/C%2B%2B-Maximum-Sliding-Window-Cheatsheet-Template!)".\n\n... | 10 | 0 | [] | 2 |
get-equal-substrings-within-budget | [Java] Simple Sliding Window, 10 lines code, Time O(N), Space O(1) | java-simple-sliding-window-10-lines-code-05cy | java\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int l = 0, r = 0, n = s.length(), cost = 0, ans = 0;\n | hiepit | NORMAL | 2019-09-29T04:25:43.150086+00:00 | 2019-09-29T04:34:54.117194+00:00 | 705 | false | ```java\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int l = 0, r = 0, n = s.length(), cost = 0, ans = 0;\n while (r < n) {\n cost += Math.abs(s.charAt(r) - t.charAt(r));\n while (cost > maxCost) {\n cost -= Math.abs(s.charAt(l... | 10 | 0 | ['Java'] | 3 |
get-equal-substrings-within-budget | [JavaScript] Easy to understand - 2 solutions | javascript-easy-to-understand-2-solution-1ddu | SOLUTION 1\n\nWe use the sliding window to solve it. The left and right means both edges of the window.\n\nSo, we could meet 2 situations when we move the right | poppinlp | NORMAL | 2019-09-29T06:15:54.824917+00:00 | 2020-05-12T10:18:58.449052+00:00 | 526 | false | ## SOLUTION 1\n\nWe use the sliding window to solve it. The `left` and `right` means both edges of the window.\n\nSo, we could meet 2 situations when we move the right edge from start to end:\n\n- The cost is less than `maxCost`: we could update the max length;\n- The cost is bigger than `maxCost`: we need to move the ... | 8 | 0 | ['JavaScript'] | 2 |
get-equal-substrings-within-budget | ✅ ⬆️ Sliding Window | Prefix Sum | Binary Search 🔥🔥 [Java] | sliding-window-prefix-sum-binary-search-350y0 | Binary Search\nTC: O(nlogn)\nSC: O(n)\n\npublic int equalSubstring(String s, String t, int maxCost) {\n int[] costs = new int[s.length() + 1]; // to i | sandeepk97 | NORMAL | 2024-05-28T00:45:21.455665+00:00 | 2024-05-28T00:50:32.286511+00:00 | 822 | false | **Binary Search**\nTC: O(nlogn)\nSC: O(n)\n```\npublic int equalSubstring(String s, String t, int maxCost) {\n int[] costs = new int[s.length() + 1]; // to include 0\n for (int i = 1; i <= s.length(); ++i) {\n costs[i] = Math.abs(s.charAt(i - 1) - t.charAt(i - 1));\n }\n\n ... | 7 | 1 | ['Binary Tree', 'Prefix Sum', 'Java'] | 7 |
get-equal-substrings-within-budget | Java | Sliding Window | 15 lines | Clean code | java-sliding-window-15-lines-clean-code-pobgk | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | judgementdey | NORMAL | 2024-05-28T00:17:45.415965+00:00 | 2024-05-28T18:02:04.226291+00:00 | 624 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n var len = 0;\n var cost = 0;\n... | 6 | 1 | ['String', 'Sliding Window', 'Java'] | 3 |
get-equal-substrings-within-budget | simplest C++ | simplest-c-by-naman238-mtd8 | \nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n vector<int> v(t.size());\n for(int i=0;i<t.size();i++)\n | naman238 | NORMAL | 2020-06-19T17:43:01.026931+00:00 | 2020-06-19T17:43:01.026980+00:00 | 307 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n vector<int> v(t.size());\n for(int i=0;i<t.size();i++)\n {\n v[i]=abs(t[i]-s[i]);\n }\n int ans=0;\n int i=0;\n int j=0;\n int k=maxCost;\n while(i<t.size... | 6 | 0 | [] | 1 |
get-equal-substrings-within-budget | Two pointers simple explanation with clean code | two-pointers-simple-explanation-with-cle-66lm | Intuition\n- We can store difference of each character from two strings in a separate list. \n- Now our problem statemenet reduces to find maximum number of ele | anupsingh556 | NORMAL | 2024-05-28T06:53:42.259419+00:00 | 2024-05-28T06:53:42.259436+00:00 | 690 | false | # Intuition\n- We can store difference of each character from two strings in a separate list. \n- Now our problem statemenet reduces to find maximum number of elements you can pick such that their sum does not exceed m we can use sliding window to solve this\n- Instead of storing difference in a separate list we can fi... | 5 | 0 | ['C++'] | 2 |
get-equal-substrings-within-budget | [Python3] Sliding Window - Two ways to implement - Easy to Understand | python3-sliding-window-two-ways-to-imple-pgpm | 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 | dolong2110 | NORMAL | 2023-04-27T17:47:06.595242+00:00 | 2023-04-27T17:47:06.595274+00:00 | 1,146 | 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)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here... | 5 | 0 | ['Sliding Window', 'Python3'] | 1 |
get-equal-substrings-within-budget | python | easy | | python-easy-by-abhishen99-apc9 | \nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n \n cost=0\n l=0\n ans=0\n for r in ra | Abhishen99 | NORMAL | 2021-07-03T16:02:16.236365+00:00 | 2021-07-03T16:02:16.236395+00:00 | 711 | false | ```\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n \n cost=0\n l=0\n ans=0\n for r in range(len(s)):\n \n cost+= abs(ord(s[r])-ord(t[r]))\n while cost > maxCost:\n cost -= abs(ord(s[l]) - ord(t[l])... | 5 | 0 | ['Python', 'Python3'] | 2 |
get-equal-substrings-within-budget | C++ Subarrray Sum Very Easy to Understand. O(N) | c-subarrray-sum-very-easy-to-understand-5bm2q | \nWe can visualise this problem as we have to maximise the length of the substring we can change in string a to string b such that it never exceeds maximum_cos | 0nurag | NORMAL | 2020-12-03T12:33:56.935431+00:00 | 2020-12-03T12:33:56.935475+00:00 | 264 | false | \nWe can visualise this problem as we have to maximise the length of the substring we can change in string a to string b such that it never exceeds maximum_cost.\n\nIt is like having a **Maximum Size Subarray Sum with sum less than k.**\n\nAlgorithm\n1. For each index (0 to n) , take absolute difference of string s an... | 5 | 0 | [] | 2 |
get-equal-substrings-within-budget | Easy to understand solution. Beginner friendly solution. O(n) Time Complexity. | easy-to-understand-solution-beginner-fri-syxk | Intuition\n Describe your first thoughts on how to solve this problem. \n1. Cost Calculation: Calculate the cost to transform each character of s to t. This giv | ShivaanjayNarula | NORMAL | 2024-07-03T00:51:25.234475+00:00 | 2024-07-03T00:51:25.234520+00:00 | 15 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. **Cost Calculation:** Calculate the cost to transform each character of s to t. This gives us the cost array.\n\n2. **Prefix Sum:** Use the prefix sum array to quickly compute the total cost of any substring.\n\n3. **Binary Search:** U... | 4 | 0 | ['Binary Search', 'Recursion', 'Sliding Window', 'Prefix Sum', 'C++'] | 0 |
get-equal-substrings-within-budget | ✅EASY AND SIMPLE SOLUTION✅ | easy-and-simple-solution-by-deleted_user-vhdc | \n\n# Code\n\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int start = 0;\n int cost = 0;\n int m | deleted_user | NORMAL | 2024-05-28T18:14:23.850304+00:00 | 2024-05-28T18:14:23.850333+00:00 | 56 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int start = 0;\n int cost = 0;\n int max_length = 0;\n\n for (int i = 0; i < s.size(); i++) {\n cost = cost + abs(s[i] - t[i]);\n\n while (cost > maxCost) {\n ... | 4 | 0 | ['C++'] | 0 |
get-equal-substrings-within-budget | JAVA Solution Explained in HINDI | java-solution-explained-in-hindi-by-the_-a5dw | https://youtu.be/h__hozHfOy0\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote | The_elite | NORMAL | 2024-05-28T14:39:03.281324+00:00 | 2024-05-28T14:39:03.281357+00:00 | 183 | false | https://youtu.be/h__hozHfOy0\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\nSubscribe Goal:- 400\nCurrent Subscriber:... | 4 | 0 | ['Java'] | 0 |
get-equal-substrings-within-budget | Bests over 98.7% users.... You can rely on this code which is self explanatory | bests-over-987-users-you-can-rely-on-thi-dyo3 | \n\n# Code\n\n\n\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n n = len(s)\n start = 0\n current_co | Aim_High_212 | NORMAL | 2024-05-28T02:12:16.997447+00:00 | 2024-05-28T02:12:16.997486+00:00 | 20 | false | \n\n# Code\n```\n\n\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n n = len(s)\n start = 0\n current_cost = 0\n max_length = 0\n\n for end in range(n):\n current_cost += abs(ord(s[end]) - ord(t[end]))\n\n while current_cost ... | 4 | 0 | ['C', 'Python', 'Java', 'Python3'] | 0 |
get-equal-substrings-within-budget | Very fast easy to understand solution | very-fast-easy-to-understand-solution-by-vfou | \n public int equalSubstring(String s1, String s2, int maxCost) {\n int []arr = new int[s1.length()];\n for(int i=0;i<s1.length();i++){\n | sk944795 | NORMAL | 2022-08-13T08:19:15.501612+00:00 | 2022-08-13T08:19:15.501642+00:00 | 475 | false | ```\n public int equalSubstring(String s1, String s2, int maxCost) {\n int []arr = new int[s1.length()];\n for(int i=0;i<s1.length();i++){\n arr[i] = Math.abs(s1.charAt(i)-s2.charAt(i)); \n }\n int i=0,j=0,sum=0,max=0;\n\n while(i<arr.length && j<arr.length){\n s... | 4 | 0 | ['Sliding Window', 'Java'] | 1 |
get-equal-substrings-within-budget | Java sliding window | java-sliding-window-by-hobiter-bzer | \n public int equalSubstring(String s, String t, int maxCost) {\n int res = 0, n = s.length();\n for (int r = 0, l = 0, diff = 0; r < n; r++) { | hobiter | NORMAL | 2020-07-18T00:04:36.502251+00:00 | 2020-07-18T00:04:36.502286+00:00 | 179 | false | ```\n public int equalSubstring(String s, String t, int maxCost) {\n int res = 0, n = s.length();\n for (int r = 0, l = 0, diff = 0; r < n; r++) {\n diff += Math.abs(s.charAt(r) - t.charAt(r));\n while (diff > maxCost) {\n diff -= Math.abs(s.charAt(l) - t.charAt(l++... | 4 | 0 | [] | 1 |
get-equal-substrings-within-budget | ✅ Beats 100% | ✅ Working 25.10.2024 | beats-100-working-25102024-by-piotr_mami-piti | python3 []\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n # Get length of input strings (they are guaranteed to b | Piotr_Maminski | NORMAL | 2024-10-25T00:01:19.171608+00:00 | 2024-10-25T00:02:43.971315+00:00 | 93 | false | ```python3 []\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n # Get length of input strings (they are guaranteed to be equal length)\n n = len(s)\n \n # Create array of transformation costs between characters at each position\n # ord() converts c... | 3 | 0 | ['PHP', 'C++', 'Java', 'Go', 'Python3', 'C#'] | 0 |
get-equal-substrings-within-budget | Simple || Sliding Window Solution || Python | simple-sliding-window-solution-python-by-4cvi | \n# Approach\nThe approach is to find the longest substring in string s that can be transformed into a substring in string t while keeping the total transformat | kunaljs | NORMAL | 2024-05-28T08:29:06.553191+00:00 | 2024-05-28T08:29:06.553212+00:00 | 234 | false | \n# Approach\nThe approach is to find the longest substring in string `s` that can be transformed into a substring in string `t` while keeping the total transformation cost within a specified limit.\n\nIt does this by comparing characters in both strings and calculating the cost of transforming each character. Then, it... | 3 | 0 | ['Two Pointers', 'Sliding Window', 'Python3'] | 4 |
get-equal-substrings-within-budget | Python | Sliding Window | python-sliding-window-by-khosiyat-kpf5 | see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n start = 0\n | Khosiyat | NORMAL | 2024-05-28T05:36:19.938315+00:00 | 2024-05-28T05:36:19.938333+00:00 | 281 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/get-equal-substrings-within-budget/submissions/1270083696/?source=submission-ac)\n\n# Code\n```\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n start = 0\n currentCost = 0\n maxLength = 0... | 3 | 0 | ['Python3'] | 0 |
get-equal-substrings-within-budget | Easiest, Understandable C++ Solution with intuition, approach, complexities and code | easiest-understandable-c-solution-with-i-tqti | Intuition\n Describe your first thoughts on how to solve this problem. \nAs question telling us to deal with costs as difference of ascii value of corresponding | itssme_jai | NORMAL | 2024-05-28T05:20:04.682611+00:00 | 2024-05-28T05:20:04.682631+00:00 | 362 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs question telling us to deal with costs as difference of ascii value of corresponding characters of s and t, so we will deal with that way only\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nnow first of all we ... | 3 | 0 | ['Sliding Window', 'C++'] | 1 |
get-equal-substrings-within-budget | Easy C++ Solution | Binary Search | Prefix Sum | Beats 100 💯✅ | easy-c-solution-binary-search-prefix-sum-hfnj | Intuition and Approach\n\nThe goal is to find the longest substring of equal length in s and t such that the sum of the absolute differences of corresponding ch | shobhitkushwaha1406 | NORMAL | 2024-05-28T01:07:50.570116+00:00 | 2024-05-28T01:07:50.570134+00:00 | 286 | false | ## Intuition and Approach\n\nThe goal is to find the longest substring of equal length in `s` and `t` such that the sum of the absolute differences of corresponding characters in this substring is less than or equal to `cost`.\n\n### Steps:\n1. **Precompute the Prefix Sum Array**: Compute a prefix sum array where each ... | 3 | 0 | ['Array', 'Binary Search', 'Prefix Sum', 'C++'] | 2 |
get-equal-substrings-within-budget | 💯✅🔥Easy Java Solution|| 12 ms ||≧◠‿◠≦✌ | easy-java-solution-12-ms-_-by-suyalneera-ut7s | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about finding the maximum length of a substring in s that is equal to th | suyalneeraj09 | NORMAL | 2024-05-28T00:35:38.246548+00:00 | 2024-05-28T00:41:34.498793+00:00 | 315 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about finding the maximum length of a substring in s that is equal to the corresponding substring in t and the sum of the absolute differences between characters in the two substrings does not exceed maxCost.\n# Approach\n<... | 3 | 0 | ['String', 'Sliding Window', 'String Matching', 'Java'] | 5 |
get-equal-substrings-within-budget | Sliding Window Solution || JAVA ;) | sliding-window-solution-java-by-kshitij_-g2p3 | \n\n# Code\n\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int maxLen =0;\n int n = s.length();\n i | Kshitij_Pandey | NORMAL | 2023-02-07T11:42:42.722172+00:00 | 2023-02-07T11:42:42.722224+00:00 | 74 | false | \n\n# Code\n```\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int maxLen =0;\n int n = s.length();\n int j=0;\n int currCost=0;\n\n for(int i=0; i<n; i++){\n //getting elemnts from the window\n char c1 = s.charAt(i);\n ... | 3 | 0 | ['Java'] | 1 |
get-equal-substrings-within-budget | [C++] - Sliding Window standard problem | c-sliding-window-standard-problem-by-mor-1z6g | \nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int currCost=0;\n int len=s.length();\n int low=0; | morning_coder | NORMAL | 2021-04-23T03:47:04.375887+00:00 | 2021-04-23T03:47:04.375929+00:00 | 333 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int currCost=0;\n int len=s.length();\n int low=0;\n int max_len=0;\n \n for(int i=0;i<len;i++){\n currCost+=abs(s[i]-t[i]);\n \n while(low<=i && currCos... | 3 | 0 | ['C', 'Sliding Window', 'C++'] | 1 |
get-equal-substrings-within-budget | Java Sliding Window | java-sliding-window-by-wushangzhen-4x42 | \nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int l = 0;\n int r = 0;\n int max = 0;\n whil | wushangzhen | NORMAL | 2019-09-29T04:03:28.612604+00:00 | 2019-09-29T04:03:28.612656+00:00 | 279 | false | ```\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n int l = 0;\n int r = 0;\n int max = 0;\n while (r < s.length()) {\n maxCost -= Math.abs(s.charAt(r) - t.charAt(r));\n r++;\n if (maxCost >= 0) {\n max = M... | 3 | 1 | [] | 2 |
get-equal-substrings-within-budget | Simple Approach : ) | simple-approach-by-adi_blessed-6upq | IntuitionThe problem requires us to find the maximum length of a substring that can be transformed from string 's' to string 't 'with a given maximum cost. The | Adi_blessed | NORMAL | 2025-01-16T07:08:28.458922+00:00 | 2025-01-16T07:08:28.458922+00:00 | 21 | false | # Intuition
The problem requires us to find the maximum length of a substring that can be transformed from string 's' to string 't 'with a given maximum cost. The cost is defined as the sum of the absolute differences between the ASCII values of the characters in the two strings at the same positions.
# Approach
Slidi... | 2 | 0 | ['Python3'] | 0 |
get-equal-substrings-within-budget | Very Easy to Understand Python Solution (Sliding Window Approach) | very-easy-to-understand-python-solution-us4q6 | Approach
💡 Approach: Sliding Window
We use the sliding window technique to efficiently find the longest substring that can be modified within the given cost.
St | Vinit_K_P | NORMAL | 2025-01-09T04:31:50.229458+00:00 | 2025-01-09T04:31:50.229458+00:00 | 31 | false | # Approach
- 💡 **Approach: Sliding Window**
We use the sliding window technique to efficiently find the longest substring that can be modified within the given cost.
**Steps:**
- Calculate the Cost Array:
Compute the difference in ASCII values for corresponding characters of s and t to form the cost array.
**Sliding... | 2 | 0 | ['Python3'] | 0 |
get-equal-substrings-within-budget | 💯🔥Constant space O(1)🎉||✅ DRY RUN || ♻️ Step wise explanation || 2 Approach💥|| 4 Lang Solution | constant-space-o1-dry-run-step-wise-expl-cd21 | Screenshot \uD83C\uDF89 \n\n\n\n\n# Intuition \uD83E\uDD14\n Describe your first thoughts on how to solve this problem. \n Given--> \n \n 1 Two string | Prakhar-002 | NORMAL | 2024-05-29T01:50:47.409274+00:00 | 2024-05-29T01:50:47.409295+00:00 | 34 | false | # Screenshot \uD83C\uDF89 \n\n\n\n\n# Intuition \uD83E\uDD14\n<!-- Describe your first thoughts on how to solve this problem. -->\n `Given`--> \n \n 1 Two string name (s) And (t) with same length\n\... | 2 | 0 | ['String', 'Binary Search', 'C', 'Sliding Window', 'Prefix Sum', 'Java', 'Python3', 'JavaScript'] | 1 |
get-equal-substrings-within-budget | simple and easy Sliding Window solution 😍❤️🔥 | simple-and-easy-sliding-window-solution-qflkm | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) \n {\n | shishirRsiam | NORMAL | 2024-05-28T19:17:35.675591+00:00 | 2024-05-28T19:17:35.675607+00:00 | 51 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) \n {\n int i = 0, j = 0;\n int ans = 0, cost = 0, n = s.size();\n while(j<n)\n {\n cost += abs(s[j] - t[j++]);\n ... | 2 | 0 | ['String', 'Sliding Window', 'C++'] | 4 |
get-equal-substrings-within-budget | Easy approach||Best Solution | easy-approachbest-solution-by-singhpayal-1pod | Intuition\nSimple intuition was to form a vector to store individual cost of each characters of string and then simply apply sliding window to find largest suba | payalsingh2212 | NORMAL | 2024-05-28T17:38:47.027277+00:00 | 2024-05-28T17:38:47.027311+00:00 | 30 | false | # Intuition\nSimple intuition was to form a vector to store individual cost of each characters of string and then simply apply sliding window to find largest subarray\n\n# Approach\n1) vector to store abs(s[i]-t[i]);\n2) sliding window (;D)\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity:O(n)\n\n# Code\n... | 2 | 0 | ['C++'] | 0 |
get-equal-substrings-within-budget | Easy C++ Sliding Window Solution⭐💯 | easy-c-sliding-window-solution-by-_risha-tywe | Longest Substring with a Maximum Cost\n\n## Intuition\nTo find the longest substring where the sum of absolute differences between corresponding characters of t | _Rishabh_96 | NORMAL | 2024-05-28T17:24:52.607411+00:00 | 2024-05-28T17:24:52.607440+00:00 | 14 | false | # Longest Substring with a Maximum Cost\n\n## Intuition\nTo find the longest substring where the sum of absolute differences between corresponding characters of two strings `s` and `t` does not exceed a given `maxCost`, we can use a sliding window approach. This technique allows us to efficiently manage the range of ch... | 2 | 0 | ['String', 'Sliding Window', 'C++'] | 0 |
get-equal-substrings-within-budget | EXPLAINED WELLL | explained-welll-by-nurliaidin-fqo9 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Compute Differences: | Nurliaidin | NORMAL | 2024-05-28T15:40:33.265297+00:00 | 2024-05-28T15:40:33.265320+00:00 | 73 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Compute Differences:** Iterate over each character of strings `s` and `t` simultaneously. For each index `i`, calculate the difference between the character codes... | 2 | 0 | ['String', 'Sliding Window', 'C++', 'JavaScript'] | 2 |
get-equal-substrings-within-budget | Easy to Understand | Simple | Clean | Crisp Code | Beats 90% | C++ | Java | Python | Kotlin | easy-to-understand-simple-clean-crisp-co-zx6j | Problem Statement\n Describe your first thoughts on how to solve this problem. \nGiven 2 strings. Find the longest possible Substring in both of them which can | Don007 | NORMAL | 2024-05-28T15:34:41.485922+00:00 | 2024-05-28T15:34:41.485942+00:00 | 157 | false | # Problem Statement\n<!-- Describe your first thoughts on how to solve this problem. -->\nGiven 2 strings. Find the longest possible Substring in both of them which can be same after applying some operations on String **s** less than **maxCost**.\n\n# Intuition and Approach\n<!-- Describe your approach to solving the p... | 2 | 0 | ['Array', 'Two Pointers', 'String', 'Binary Search', 'Sliding Window', 'Prefix Sum', 'C++', 'Java', 'Python3', 'Kotlin'] | 0 |
get-equal-substrings-within-budget | Easy Sliding Window | easy-sliding-window-by-anshubaloria123-xf0w | Intuition\n Describe your first thoughts on how to solve this problem. \nsliding window\n\n# Approach\n Describe your approach to solving the problem. keep addi | anshubaloria123 | NORMAL | 2024-05-28T10:35:19.456398+00:00 | 2024-05-28T10:35:19.456417+00:00 | 24 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nsliding window\n\n# Approach\n<!-- Describe your approach to solving the problem. -->keep adding the current difference value until it is less then max value once it cross , then increse the previous pointer till it is less then max value... | 2 | 0 | ['Java'] | 1 |
get-equal-substrings-within-budget | Simple Two Pointer Approach!! | simple-two-pointer-approach-by-tsahu9461-kbrn | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\npublic:\n int equ | tsahu9461 | NORMAL | 2024-05-28T07:46:35.789833+00:00 | 2024-05-28T07:46:35.789866+00:00 | 5 | false | # Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int left = 0; //to keep track of the first element in every substring\n int right... | 2 | 0 | ['Array', 'Two Pointers', 'Sliding Window', 'C++'] | 1 |
get-equal-substrings-within-budget | EASY WINDOW MAKINS SOLUTION || IN DEPTH APPROACH . | easy-window-makins-solution-in-depth-app-4e36 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n- You have two strings s and t of the same length.\n- There\'s a cost associated with | Abhishekkant135 | NORMAL | 2024-05-28T07:15:30.914598+00:00 | 2024-05-28T07:15:30.914614+00:00 | 47 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n- You have two strings `s` and `t` of the same length.\n- There\'s a cost associated with changing a character in `s` to the corresponding character in `t`. The cost is the absolute difference between their ASCII values.\n- The code fin... | 2 | 0 | ['Sliding Window', 'Java'] | 0 |
get-equal-substrings-within-budget | Simple Solution using Sliding Window - Beats 100% T.C O(N) | simple-solution-using-sliding-window-bea-yuer | Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to find the longest substring in s such that changing it to match t costs no mo | nobody_me | NORMAL | 2024-05-28T06:09:18.733758+00:00 | 2024-05-28T06:09:18.733774+00:00 | 61 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to find the longest substring in s such that changing it to match t costs no more than maxCost. The cost of changing a character `s[i]` to `t[i]` is the absolute difference `abs(s[i] - t[i])`\n\n# Sliding Window Approach\n<!-- Des... | 2 | 0 | ['Two Pointers', 'String', 'Sliding Window', 'Prefix Sum', 'C++'] | 1 |
get-equal-substrings-within-budget | Use Sliding Window To Get Maximum Window Size | Java | C++ | use-sliding-window-to-get-maximum-window-pwtk | Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/gJQsXRKX7bI\n# Code\nC++\n\nclass Solution {\npublic:\n int equal | Lazy_Potato_ | NORMAL | 2024-05-28T05:28:48.190585+00:00 | 2024-05-28T05:28:48.190601+00:00 | 150 | false | # Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/gJQsXRKX7bI\n# Code\nC++\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int leftPtr = 0, size = s.size(), rightPtr = 0;\n int currCost = 0, maxLen = 0;\n while(ri... | 2 | 0 | ['String', 'Sliding Window', 'C++', 'Java'] | 1 |
get-equal-substrings-within-budget | C# Solution for Get Equal Substrings Within Budget Problem | c-solution-for-get-equal-substrings-with-sqpd | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind using a prefix sum array and binary search is to efficiently calcu | Aman_Raj_Sinha | NORMAL | 2024-05-28T04:27:18.565294+00:00 | 2024-05-28T04:27:18.565311+00:00 | 98 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind using a prefix sum array and binary search is to efficiently calculate the cost of transforming any substring of s to t and then use binary search to find the maximum length of a valid substring within the given cost ... | 2 | 0 | ['C#'] | 1 |
get-equal-substrings-within-budget | Sliding Window 2 Approaches | sliding-window-2-approaches-by-himanshum-hsxu | Sliding window with Prefix sum\n# Code\n\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n=s.length();\n | himanshumude01 | NORMAL | 2024-05-28T04:21:33.860953+00:00 | 2024-05-28T04:21:33.860979+00:00 | 37 | false | # Sliding window with Prefix sum\n# Code\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n=s.length();\n vector<int>pref(n,0);\n pref[0]=abs(s[0]-t[0]);\n for(int i=1;i<n;i++)\n {\n pref[i]=pref[i-1]+abs(s[i]-t[i]);\n ... | 2 | 0 | ['C++'] | 0 |
get-equal-substrings-within-budget | Binary Search + Sliding Window (MENTOSS ZINDAGIIIIII) | binary-search-sliding-window-mentoss-zin-jlcq | \n\n# Complexity\n- Time complexity:O(n*log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O( | TechTinkerer | NORMAL | 2024-05-28T04:13:54.361750+00:00 | 2024-05-28T04:13:54.361782+00:00 | 47 | false | \n\n# Complexity\n- Time complexity:O(n*log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool check(int wins,vector<int>&v,int maxcost){\n int i=0,j=0;\n int n=v.... | 1 | 0 | ['Binary Search', 'Sliding Window', 'C++'] | 0 |
get-equal-substrings-within-budget | 🏆💢💯 Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅💥🔥💫Explained☠💥🔥 Beats 💯 | faster-lesser-cpython3javacpythonexplain-0xt0 | Intuition\n\n\nC++ []\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int l = 0, curr = 0, cnt = 0;\n for | Edwards310 | NORMAL | 2024-05-28T03:49:55.002160+00:00 | 2024-05-28T03:49:55.002183+00:00 | 62 | false | # Intuition\n\n\n```C++ []\nclass Solution {\npublic:\n int ... | 2 | 0 | ['String', 'Binary Search', 'C', 'Sliding Window', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'C#'] | 0 |
get-equal-substrings-within-budget | 💯✅🔥Easy ☕Java☕ Solution|| 7 ms ||≧◠‿◠≦✌ | easy-java-solution-7-ms-_-by-sreehithsan-7sbz | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is essentially about finding the longest substring in "s" that can be trans | sreehithsanam | NORMAL | 2024-05-28T03:01:11.147093+00:00 | 2024-05-28T03:01:11.147118+00:00 | 2 | false | # *Intuition*\n<!-- Describe your first thoughts on how to solve this problem. -->\n*The problem is essentially about finding the longest substring in "s" that can be transformed into the corresponding substring in "t" with a limited cost. The cost is defined as the sum of the absolute differences of the ASCII values o... | 2 | 0 | ['String', 'Sliding Window', 'Java'] | 0 |
get-equal-substrings-within-budget | [C++] Binary Search the Maximum Length | c-binary-search-the-maximum-length-by-aw-cb1h | Intuition\n Describe your first thoughts on how to solve this problem. \n- Define a boolean function check(length) that can check if there exists a substring wi | pepe-the-frog | NORMAL | 2024-05-28T01:43:21.434637+00:00 | 2024-05-28T01:43:21.434659+00:00 | 339 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Define a boolean function `check(length)` that can check if there exists a substring with `length` meets the condition\n- The `check(length)` is a function like this:\n - `f(0) = true`, `f(1) = true`, ... `f(x) = true`, `f(x + 1) = fal... | 2 | 0 | ['C++'] | 3 |
get-equal-substrings-within-budget | Sliding Window Technique || beats 93% users with C++ & 85% with java || python3 || typescript | sliding-window-technique-beats-93-users-pi8gx | Approach\nSliding Window Technique\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Explanation\n1. Initialize Variables:\n\n- n: Lengt | SanketSawant18 | NORMAL | 2024-05-28T00:51:32.547067+00:00 | 2024-05-28T00:51:32.547102+00:00 | 238 | false | # Approach\nSliding Window Technique\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Explanation\n1. **Initialize Variables:**\n\n- n: Length of the strings s and t.\n- maxLength: To store the maximum length of the valid substring found.\n- currentCost: To track the total cost of the current w... | 2 | 0 | ['String', 'Sliding Window', 'C++', 'Java', 'TypeScript', 'Python3'] | 1 |
get-equal-substrings-within-budget | Python3 || O(n) and O(1) TIME AND SPACE || May 28 2024 Daily | python3-on-and-o1-time-and-space-may-28-fou5j | Intuition\nThe problem requires finding the maximum length of a substring in string s that can be transformed into the corresponding substring in string t with | praneelpa | NORMAL | 2024-05-28T00:04:31.198443+00:00 | 2024-05-28T00:04:31.198461+00:00 | 140 | false | # Intuition\nThe problem requires finding the maximum length of a substring in string s that can be transformed into the corresponding substring in string t with a cost less than or equal to maxCost. We can approach this problem using a sliding window technique.\n\n# Approach\nSliding Window: Initialize two pointers i ... | 2 | 0 | ['Python3'] | 1 |
get-equal-substrings-within-budget | Sliding window & Two Pointers Pattern | sliding-window-two-pointers-pattern-by-d-wqo3 | \n# Code\n\n// Exact same as some problem add it for reference\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n\n in | Dixon_N | NORMAL | 2024-05-20T02:09:52.692431+00:00 | 2024-05-20T02:09:52.692460+00:00 | 29 | false | \n# Code\n```\n// Exact same as some problem add it for reference\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n\n int maxLength=0,left=0,right=0;\n int n=s.length();\n\n while(right<n){\n\n int diff = Math.abs(s.charAt(right)-t.charAt(right));\n ... | 2 | 0 | ['Java'] | 0 |
get-equal-substrings-within-budget | C++ || easy | c-easy-by-shradhaydham24-sm83 | 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 | shradhaydham24 | NORMAL | 2023-07-16T15:42:44.164231+00:00 | 2023-07-16T15:42:44.164251+00:00 | 235 | 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++'] | 1 |
get-equal-substrings-within-budget | Very Simple, C++ Longest Sub-Array Sum ✅✅ | very-simple-c-longest-sub-array-sum-by-d-dd18 | if it Helps You. Please UpVote Me...! \u2764\n# Approach\n Describe your approach to solving the problem. \n\nApproach is Simple But we have to change the probl | Deepak_5910 | NORMAL | 2023-06-13T09:50:46.760021+00:00 | 2023-06-13T09:50:46.760045+00:00 | 273 | false | # if it Helps You. Please UpVote Me...! \u2764\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nApproach is Simple But we have to change the problem Statement to **Longest Sub-Array with Sum <=K.**\n\n**Just Follow the Below Points to change the Problem Statement:-**\n1. Calculate the absolute Co... | 2 | 0 | ['Sliding Window', 'Prefix Sum', 'C++'] | 1 |
get-equal-substrings-within-budget | ✅✅C++ USING SLIDING WINDOW|| EASY TO UNDERSTAND✅✅ | c-using-sliding-window-easy-to-understan-rszg | \nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxc) {\n int sum=0,i=0,j=0,ans=0;\n while(j<s.size())\n {\n | Satyam_9766 | NORMAL | 2023-04-22T11:53:53.885859+00:00 | 2023-04-22T11:53:53.885892+00:00 | 278 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxc) {\n int sum=0,i=0,j=0,ans=0;\n while(j<s.size())\n {\n int a = s[j]-\'a\';\n int b = t[j]-\'a\';\n sum+= abs(a-b);\n if(sum<=maxc)\n {\n j++;\n ... | 2 | 0 | ['C', 'C++'] | 0 |
get-equal-substrings-within-budget | Php | Beats 100% Runtime and memory | php-beats-100-runtime-and-memory-by-kaur-17n7 | 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 | kaursanampreet | NORMAL | 2023-04-02T04:42:19.309087+00:00 | 2023-04-02T04:42:19.309120+00:00 | 219 | 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 | ['PHP'] | 1 |
get-equal-substrings-within-budget | ✅ C++ || 3 Lines only || Sliding window | c-3-lines-only-sliding-window-by-t86-rmwb | c++\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost, int res = 0) {\n for (int i = 0, left = 0, counting = 0; i < cost | t86 | NORMAL | 2023-01-11T23:57:19.951261+00:00 | 2023-03-24T20:12:18.610082+00:00 | 139 | false | ```c++\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost, int res = 0) {\n for (int i = 0, left = 0, counting = 0; i < cost.size(); i++) {\n counting += abs(s[i] - t[i]);\n while (counting > maxCost) counting -= cost[left++];\n res = max(res, i - ... | 2 | 1 | [] | 0 |
get-equal-substrings-within-budget | [C++/Python] | Sliding window | cpython-sliding-window-by-tusharbhart-b6xm | C++\n\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int ans = 0, c = maxCost, i = 0, j = 0;\n\n for(int | TusharBhart | NORMAL | 2022-10-02T17:34:09.945253+00:00 | 2022-10-02T17:34:09.945298+00:00 | 548 | false | # C++\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int ans = 0, c = maxCost, i = 0, j = 0;\n\n for(int j=0; j<s.size(); j++) {\n c -= abs(s[j] - t[j]);\n if(c >= 0) ans = max(ans, j - i + 1);\n else c += abs(s[i] - t[i]), i++... | 2 | 0 | ['Sliding Window', 'Python', 'C++'] | 1 |
get-equal-substrings-within-budget | python solution with sliding window | python-solution-with-sliding-window-by-d-4jcy | \n\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n if maxCost == 0 and s!=t:\n return 1\n res = | derrickyu | NORMAL | 2022-09-19T08:12:37.848842+00:00 | 2022-09-19T08:12:37.848877+00:00 | 412 | false | \n```\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n if maxCost == 0 and s!=t:\n return 1\n res = 0\n m={\'a\':1,\'b\':2,\'c\':3,\'d\':4,\'e\':5,\'f\':6,\'g\':7,\'h\':8,\'i\':9,\'j\':10,\'k\':11,\'l\':12,\'m\':13,\'n\':14,\'o\':15,\'p\':16,\'q\':17... | 2 | 0 | ['Sliding Window', 'Python'] | 1 |
get-equal-substrings-within-budget | C# Solution | Time: O(n), Memory: O(1) | Easy to understand, Sliding window | c-solution-time-on-memory-o1-easy-to-und-2e57 | C#\npublic class Solution {\n public int EqualSubstring(string s, string t, int maxCost) {\n int cost = 0, start = 0, end = 0;\n while (end < s | tonytroeff | NORMAL | 2022-08-22T06:37:27.230215+00:00 | 2022-08-22T06:37:27.230255+00:00 | 265 | false | ```C#\npublic class Solution {\n public int EqualSubstring(string s, string t, int maxCost) {\n int cost = 0, start = 0, end = 0;\n while (end < s.Length) {\n cost += Math.Abs(s[end] - t[end]);\n if (cost > maxCost) {\n cost -= Math.Abs(s[start] - t[start]);\n ... | 2 | 0 | ['Sliding Window'] | 1 |
get-equal-substrings-within-budget | C++ | Sliding Window | Template | Easy | c-sliding-window-template-easy-by-jaidee-5xpb | Do upvote if it helps! :)\n\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n=s.size();\n vector<int>dif | jaideep_ankur | NORMAL | 2022-02-05T17:44:30.569365+00:00 | 2022-02-05T17:44:30.569403+00:00 | 144 | false | **Do upvote if it helps! :)**\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n=s.size();\n vector<int>diff(n,0);\n for(int i=0;i<n;i++){\n diff[i]=abs((s[i]-\'a\')-(t[i]-\'a\'));\n }\n int res=0,left=0,k=maxCost,sum=0;\n ... | 2 | 0 | ['C', 'Sliding Window'] | 1 |
get-equal-substrings-within-budget | Java || Sliding Window || T.C - O(n) S.C - O(1) | java-sliding-window-tc-on-sc-o1-by-legen-qs2r | \n public int equalSubstring(String s, String t, int maxCost) {\n\n\t\tint len = s.length(), max = 0, idx1 = -1, idx2 = 0, cost = 0;\n\n\t\twhile (idx2 < len | LegendaryCoder | NORMAL | 2021-04-19T17:59:30.195133+00:00 | 2021-04-19T17:59:30.195180+00:00 | 36 | false | \n public int equalSubstring(String s, String t, int maxCost) {\n\n\t\tint len = s.length(), max = 0, idx1 = -1, idx2 = 0, cost = 0;\n\n\t\twhile (idx2 < len) {\n\n\t\t\twhile (idx2 < len) {\n\t\t\t\tcost += Math.abs(s.charAt(idx2) - t.charAt(idx2));\n\t\t\t\tif (cost <= maxCost) {\n\t\t\t\t\tif (idx2 - idx1 > max)\... | 2 | 1 | [] | 0 |
get-equal-substrings-within-budget | Binary Search + sliding window | binary-search-sliding-window-by-just_mik-9fp0 | \nbool fun(int len,string s,string t,int maxcost,int n)\n {\n int temp=0,cost=0;\n for(int i=0;i<n;i++)\n {\n cost+=(abs((s[i | just_miku | NORMAL | 2020-10-13T05:26:06.000752+00:00 | 2020-10-13T05:26:06.000800+00:00 | 124 | false | ```\nbool fun(int len,string s,string t,int maxcost,int n)\n {\n int temp=0,cost=0;\n for(int i=0;i<n;i++)\n {\n cost+=(abs((s[i]-\'a\')-(t[i]-\'a\')));\n }\n for(int i=n;i<len;i++)\n {\n if(cost<=maxcost) return(1);\n cost+=(abs((s[i]-\'a\')... | 2 | 1 | ['Sliding Window', 'Binary Tree'] | 1 |
get-equal-substrings-within-budget | C# - Sliding window - easy & efficient code | c-sliding-window-easy-efficient-code-by-60sp1 | Please upvote and comment if you like the solution!\n```\n public int EqualSubstring(string s, string t, int maxCost) {\n\tint n = s.Length, left = 0, window = | stack_360 | NORMAL | 2020-08-15T19:45:36.263135+00:00 | 2020-08-15T19:58:15.433637+00:00 | 72 | false | Please upvote and comment if you like the solution!\n```\n public int EqualSubstring(string s, string t, int maxCost) {\n\tint n = s.Length, left = 0, window = 0, ans = int.MinValue;\n\tint[] cost = new int[n];\n\tfor (int right = 0; right < n; right++)\n\t{\n\t\tcost[right] = Math.Abs(s[right] - t[right]);\n\t\twindow... | 2 | 0 | [] | 0 |
get-equal-substrings-within-budget | C++: Sliding Window || O(n) Solution | c-sliding-window-on-solution-by-bingabid-1lfk | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n = s.length();\n int left=0,right=0,ans=0,cost=0; | bingabid | NORMAL | 2020-06-16T06:11:17.424813+00:00 | 2020-06-16T06:11:17.424860+00:00 | 101 | false | ```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n int n = s.length();\n int left=0,right=0,ans=0,cost=0;\n while(right<n){\n cost= cost + abs(s[right]-t[right]);\n while(cost>maxCost){\n cost= cost - abs(s[left]-t[left])... | 2 | 0 | [] | 0 |
get-equal-substrings-within-budget | C++ | Sliding Window Standard Problem | O(n) | c-sliding-window-standard-problem-on-by-sbfsy | Intuition:\n\nTrack using two pointers and keep on adding the cost in variable and keep on increasing the window towards right.\nOnce the variable value exceed | wh0ami | NORMAL | 2020-05-28T19:17:08.277610+00:00 | 2020-05-28T19:17:08.277649+00:00 | 108 | false | **Intuition:**\n\nTrack using two pointers and keep on adding the cost in variable and keep on increasing the window towards right.\nOnce the variable value exceed maxcost, reduce the window size from left.\n\n**Solution:**\n\n```\nclass Solution {\npublic:\n int equalSubstring(string s, string t, int maxCost) {\n ... | 2 | 0 | [] | 0 |
get-equal-substrings-within-budget | [java] simple solution based on two pointers | java-simple-solution-based-on-two-pointe-v1ml | \nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n if(maxCost < 0 || s == null || t == null || s.length() != t.length | liyun1988 | NORMAL | 2019-09-29T05:49:38.924707+00:00 | 2019-09-29T05:49:38.924762+00:00 | 132 | false | ```\nclass Solution {\n public int equalSubstring(String s, String t, int maxCost) {\n if(maxCost < 0 || s == null || t == null || s.length() != t.length() || s.length() == 0) {\n return 0;\n }\n \n int[] diffs = new int[s.length()];\n int left = 0, cost = 0, maxLen = 0;... | 2 | 0 | [] | 0 |
get-equal-substrings-within-budget | Two Pointer | Simple Solution | Time O(n), Space O(n) | two-pointer-simple-solution-time-on-spac-a2q2 | ```\n public int equalSubstring(String s, String t, int maxCost) {\n int l = s.length();\n int[] nums = new int[l];\n for(int i=0; i<s.l | popeye_the_sailort | NORMAL | 2019-09-29T04:01:51.759344+00:00 | 2019-09-29T04:01:51.759396+00:00 | 256 | false | ```\n public int equalSubstring(String s, String t, int maxCost) {\n int l = s.length();\n int[] nums = new int[l];\n for(int i=0; i<s.length(); ++i) {\n nums[i] = Math.abs(s.charAt(i) - t.charAt(i));\n }\n int len = 0;\n int sum = 0;\n for(int i=0, j=0; i<... | 2 | 1 | [] | 1 |
get-equal-substrings-within-budget | Sliding window || Java || Easy || 🚀🚀 || 🔥🔥 | sliding-window-java-easy-by-vermaanshul9-ruof | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | vermaanshul975 | NORMAL | 2025-03-23T07:32:41.195534+00:00 | 2025-03-23T07:32:41.195534+00:00 | 17 | 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
`... | 1 | 0 | ['Java'] | 0 |
get-equal-substrings-within-budget | Simple C++ Solution || Sliding window || C++ | simple-c-solution-sliding-window-c-by-ab-5e2g | IntuitionWe want to find the maximum length of a substring where the total transformation cost from s[i] to t[i] is less than or equal to maxCost.
If the cost e | Abhinandanpatil02 | NORMAL | 2025-03-18T07:19:07.911699+00:00 | 2025-03-18T07:19:07.911699+00:00 | 17 | false | ---
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We want to find the **maximum length of a substring** where the **total transformation cost from `s[i]` to `t[i]` is less than or equal to `maxCost`**.
If the cost exceeds `maxCost`, we need to **remove characters from the start of t... | 1 | 0 | ['C++'] | 0 |
get-equal-substrings-within-budget | Easy to Understand || Sliding Window & 2 Pointers || C++ || Java || Python || Javascript | easy-to-understand-sliding-window-2-poin-ddbi | Complexity
Time complexity:
O(n)
Space complexity:
O(1)
Code | rajshingala | NORMAL | 2025-03-12T16:47:44.358500+00:00 | 2025-03-12T16:47:44.358500+00:00 | 26 | false | # Complexity
- Time complexity:
$$O(n)$$
- Space complexity:
$$O(1)$$
# Code
```cpp []
class Solution {
public:
int equalSubstring(string s, string t, int maxCost) {
int n = s.length();
int l = 0;
int r = 0;
int cost = 0;
int maxLen = 0;
while(r < n) {
... | 1 | 0 | ['Two Pointers', 'Sliding Window', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
get-equal-substrings-within-budget | C# | c-by-adchoudhary-mffo | Code | adchoudhary | NORMAL | 2025-03-11T04:00:29.042359+00:00 | 2025-03-11T04:00:29.042359+00:00 | 3 | false | # Code
```csharp []
public class Solution {
public int EqualSubstring(string s, string t, int maxCost)
{
int N = s.Length;
int maxLen = 0;
// Starting index of the current substring
int start = 0;
// Cost of converting the current substring in s to t
int currCost = 0;
... | 1 | 0 | ['C#'] | 0 |
get-equal-substrings-within-budget | Sliding window solution using Python3!! | sliding-window-solution-using-python3-by-6sd0 | Intuition
The goal is to find the maximum length of a contiguous substring of s that can be changed to its corresponding substring in t without the total cost | Sivamani_R | NORMAL | 2025-03-09T12:31:11.847835+00:00 | 2025-03-09T12:31:11.847835+00:00 | 17 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. ***The goal is to find the maximum length of a contiguous substring of*** `s` ***that can be changed to its corresponding substring in*** `t` ***without the total cost exceeding*** `maxCost`.
1. ***Changing a character*** `s[i]` ***to**... | 1 | 0 | ['String', 'Sliding Window', 'Python3'] | 0 |
get-equal-substrings-within-budget | Short code. One pass. Beats 100%. | short-code-one-pass-beats-100-by-rickien-iu15 | IntuitionMaintain the maximum result found up to the ith charactor.ApproachWhen adding the cost of changing the ith charactor, check the accumulated cost, if sm | rickienol | NORMAL | 2025-03-07T04:04:55.605776+00:00 | 2025-03-07T04:04:55.605776+00:00 | 15 | false | # Intuition
Maintain the maximum result found up to the ith charactor.
# Approach
When adding the cost of changing the ith charactor, check the accumulated cost, if small enough, increase result by 1; otherwise, keep the result unchanged, and remove the cost from the first of the current window (the (i-res)th charact... | 1 | 0 | ['C++'] | 0 |
get-equal-substrings-within-budget | Easy Java Solution || Beats 98% of Java Users . | easy-java-solution-beats-98-of-java-user-wl7e | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | zzzz9 | NORMAL | 2025-02-12T16:35:19.476277+00:00 | 2025-02-12T16:35:19.476277+00:00 | 26 | 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
`... | 1 | 0 | ['String', 'Sliding Window', 'Prefix Sum', 'Java'] | 0 |
get-equal-substrings-within-budget | Python, Sliding Window, T=O(n), S=O(1) | python-sliding-window-ton-so1-by-aakarsh-rxcd | Intuition
This problem can be solved by Sliding Window approach, as maximum length of substring is asked.
Idea is to keep expanding the window to right in each | Aakarsh-Lohani | NORMAL | 2025-01-14T18:47:57.029419+00:00 | 2025-01-14T18:49:28.020440+00:00 | 19 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. This problem can be solved by Sliding Window approach, as maximum length of substring is asked.
2. Idea is to keep expanding the window to right in each step and shrinking it from left, if it exceeds the maxCost.
# Approach
<!-- Describ... | 1 | 0 | ['String', 'Sliding Window', 'Python3'] | 0 |
get-equal-substrings-within-budget | Simple O(n) | simple-on-by-sansk_ritu-0q5k | IntuitionThe cost is defined by diff of chars at corresponding index of both the strings.ApproachCalculate cost of each index by taking difference and store the | Sansk_Ritu | NORMAL | 2024-12-26T14:38:46.030633+00:00 | 2024-12-26T14:38:46.030633+00:00 | 18 | false | # Intuition
The cost is defined by diff of chars at corresponding index of both the strings.
# Approach
Calculate cost of each index by taking difference and store them in a vector. Now in the vector, look for longest subset with sum less than or equal to maxCost.
# Complexity
- Time complexity:
O(n)
- Space comple... | 1 | 0 | ['Sliding Window', 'C++'] | 0 |
get-equal-substrings-within-budget | Beats 100% users🔥 | Approach explained✅ | Well-commented code | beats-100-users-approach-explained-well-ntbad | Approach\n- Use two pointers (start and end) to represent the current window.\n- Expand the window by moving the end pointer and calculate the cost of transform | sleekGeek28 | NORMAL | 2024-12-05T16:18:55.538543+00:00 | 2024-12-05T16:18:55.538581+00:00 | 19 | false | # Approach\n- Use two pointers (start and end) to represent the current window.\n- Expand the window by moving the end pointer and calculate the cost of transforming the substring `s[start:end]`into `t[start:end]`.\n- If the total cost exceeds maxCost, shrink the window by moving the start pointer and reducing the cost... | 1 | 0 | ['String', 'Sliding Window', 'C++'] | 1 |
get-equal-substrings-within-budget | Must Watch✅💯Easiest Sliding Window Approach With Detailed Explanation💯✅ | must-watcheasiest-sliding-window-approac-nzxi | Intuition\n- Given two strings s and t of equal length, and an integer maxCost, the task is to find the maximum length of a substring that can be made equal to | Ajay_Kartheek | NORMAL | 2024-09-11T20:47:24.892317+00:00 | 2024-09-11T20:47:24.892346+00:00 | 3 | false | # Intuition\n- Given two strings s and t of equal length, and an integer maxCost, the task is to find the maximum length of a substring that can be made equal to the corresponding substring of t by changing characters in s, where the cost of changing a character is the absolute difference between their ASCII values. Th... | 1 | 0 | ['String', 'Sliding Window', 'C++', 'Java', 'Python3'] | 0 |
get-equal-substrings-within-budget | Java O(N) Soln | Beats 99.3% in TC | Good Readability | Beginner's Friendly | java-on-soln-beats-993-in-tc-good-readab-of1y | 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 | karan_s01 | NORMAL | 2024-08-26T16:27:49.532466+00:00 | 2024-08-26T16:28:18.411870+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 : O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : O(N)\n<!-- Add your space complexity here, e.g.... | 1 | 0 | ['String', 'Sliding Window', 'Java'] | 0 |
get-equal-substrings-within-budget | 💯Beats 97%💯 Faster✅ Sliding Window 🔥🎯Java☕ | beats-97-faster-sliding-window-java-by-v-j1yv | Intuition\nTo find the maximum length of a substring that can be transformed within a given cost, we can utilize a sliding window approach. By maintaining a win | vanshtrivedi12345 | NORMAL | 2024-06-01T11:00:40.758693+00:00 | 2024-06-01T11:00:40.758736+00:00 | 1 | false | # Intuition\nTo find the maximum length of a substring that can be transformed within a given cost, we can utilize a sliding window approach. By maintaining a window with two pointers, we can efficiently calculate the cost of transforming the substring and adjust the window size to maximize the length without exceeding... | 1 | 0 | ['Java'] | 0 |
get-equal-substrings-within-budget | Python 3 solution (sliding window) | python-3-solution-sliding-window-by-iloa-dbgs | Code\npy\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n costs = [abs(ord(a) - ord(b)) for a, b in zip(s, t)]\n | iloabachie | NORMAL | 2024-05-31T19:03:21.520996+00:00 | 2024-05-31T19:03:21.521028+00:00 | 1 | false | # Code\n```py\nclass Solution:\n def equalSubstring(self, s: str, t: str, maxCost: int) -> int:\n costs = [abs(ord(a) - ord(b)) for a, b in zip(s, t)]\n left = result = total = 0\n for right in range(len(costs)):\n total += costs[right]\n while left <= right and total > max... | 1 | 0 | ['Python3'] | 0 |
get-equal-substrings-within-budget | Simple and easy solution with comments ✅✅ | simple-and-easy-solution-with-comments-b-an5j | Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | vaibhav2112 | NORMAL | 2024-05-30T15:13:59.902314+00:00 | 2024-05-30T15:13:59.902348+00:00 | 0 | false | # Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n // Method 1 - Sliding window\n // TC = O(N), SC = O(1)\n int equalSubstring(string s, st... | 1 | 0 | ['C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.