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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
longest-increasing-subsequence-ii | [Java] Original LIS solution (No segment tree) | java-original-lis-solution-no-segment-tr-7x4o | Use the same idea as the original LIS, just instead of storing the smallest possible number, here we need to store the whole sequence.\n\n\n public int lengt | wddd | NORMAL | 2022-09-11T05:36:58.049556+00:00 | 2022-09-14T02:27:38.611803+00:00 | 644 | false | Use the same idea as the original LIS, just instead of storing the smallest possible number, here we need to store the whole sequence.\n\n```\n public int lengthOfLIS(int[] nums, int k) {\n List<List<Integer>> tails = new ArrayList<>();\n\n for (int num : nums) {\n int ind = Collections.bina... | 1 | 0 | ['Binary Tree'] | 0 |
longest-increasing-subsequence-ii | javascript Segment Tree Range Min Query 281ms | javascript-segment-tree-range-min-query-jc3yf | \n///////////////////////////////////////////// Template ///////////////////////////////////////////////////////////\n// using array format\nfunction SegmentTre | henrychen222 | NORMAL | 2022-09-11T05:28:09.621797+00:00 | 2022-09-11T05:36:54.705988+00:00 | 233 | false | ```\n///////////////////////////////////////////// Template ///////////////////////////////////////////////////////////\n// using array format\nfunction SegmentTreeRMQ(n) {\n let h = Math.ceil(Math.log2(n)), len = 2 * 2 ** h, a = Array(len).fill(Number.MAX_SAFE_INTEGER);\n h = 2 ** h;\n return { update, minx, ... | 1 | 0 | ['Tree', 'JavaScript'] | 1 |
longest-increasing-subsequence-ii | Rust | Segment Tree | With Comments | rust-segment-tree-with-comments-by-walli-vvdf | This is my unrevised submission for the 2022-09-11 Weekly Contest 310. This is a DP problem - add one to the path length of the longest path found so far among | wallicent | NORMAL | 2022-09-11T04:28:32.123891+00:00 | 2022-09-11T10:51:06.424577+00:00 | 138 | false | This is my unrevised submission for the 2022-09-11 Weekly Contest 310. This is a DP problem - add one to the path length of the longest path found so far among the numbers that are no less than k smaller than the current number. But the difficult part is that the O(n^2) needed for a standard implementation is too slow.... | 1 | 0 | ['Rust'] | 1 |
longest-increasing-subsequence-ii | [Python3] segment tree | python3-segment-tree-by-ye15-9cio | Please pull this commit for solutions of weekly 310. \n\n\nclass SegTree: \n\n def __init__(self, arr: List[int]): \n self.n = len(arr)\n self. | ye15 | NORMAL | 2022-09-11T04:20:04.126765+00:00 | 2022-09-14T19:47:49.639582+00:00 | 1,106 | false | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/b89b2c654a0b8ced9885ecdb433ad5f929a1d4b4) for solutions of weekly 310. \n\n```\nclass SegTree: \n\n def __init__(self, arr: List[int]): \n self.n = len(arr)\n self.tree = [0] * (2*self.n)\n # for i in range(2*self.n-1, 0, -1... | 1 | 0 | ['Python3'] | 2 |
longest-increasing-subsequence-ii | Segment Tree || C++ | segment-tree-c-by-kishan_akbari-5plj | Firstly,you have to create array of size 1e5+100, because values of array is 1<=v[i]<=1e5. Assume that Array name is \'Seg\'\nNow, you have to insert elements o | Kishan_Akbari | NORMAL | 2022-09-11T04:08:13.619590+00:00 | 2022-09-11T04:08:13.619617+00:00 | 232 | false | Firstly,you have to create array of size 1e5+100, because values of array is 1<=v[i]<=1e5. Assume that Array name is \'Seg\'\nNow, you have to insert elements one by one. Assume that you Reached element at index i and value of that element is X. now you have to find maximam value of rang Seg[X-k,X-1]. To find this maxi... | 1 | 0 | ['Dynamic Programming'] | 0 |
longest-increasing-subsequence-ii | [C++] An easy solution using segment tree | c-an-easy-solution-using-segment-tree-by-zd43 | \n// find smallest x s.t. n <= 2^x\nint ceil_pow2(int n) {\n int x = 0;\n while ((1U << x) < (unsigned int)(n)) x++;\n return x;\n}\n\n// segment tree\ | martin0327 | NORMAL | 2022-09-11T04:03:05.776010+00:00 | 2022-09-11T05:19:47.704180+00:00 | 285 | false | ```\n// find smallest x s.t. n <= 2^x\nint ceil_pow2(int n) {\n int x = 0;\n while ((1U << x) < (unsigned int)(n)) x++;\n return x;\n}\n\n// segment tree\ntemplate <class S, S (*op)(S, S), S (*e)()> struct segtree {\n public:\n segtree() : segtree(0) {}\n segtree(int n) : segtree(std::vector<S>(n, e()))... | 1 | 1 | ['Dynamic Programming', 'Tree'] | 0 |
longest-increasing-subsequence-ii | c++ dp || o(nlog(n)) || SEGMENT TREE | c-dp-onlogn-segment-tree-by-aniketash57-n00d | \n\t/*\n\t\tsubproblem first you guys can try finding longest increasing subsequence in nlog(n) using a map \n\t\tafter that instead of map if you use segment t | aniketash57 | NORMAL | 2022-09-11T04:01:07.004273+00:00 | 2022-09-11T04:37:29.813056+00:00 | 1,100 | false | ```\n\t/*\n\t\tsubproblem first you guys can try finding longest increasing subsequence in nlog(n) using a map \n\t\tafter that instead of map if you use segment tree you can find max of k elements smaller than current element in logirithmic time \n\t*/\n\tstruct node{\n\t\tint x;\n\t\tnode()\n\t\t{\n\t\t\tx=-inf;\n\t\... | 1 | 0 | ['Dynamic Programming', 'Tree'] | 0 |
longest-increasing-subsequence-ii | Segment Tree | segment-tree-by-java_programmer_ketan-raml | \n/*\n This can be solved using a segment tree\n Time Complexity -> O(NlogN)\n Space Complexity -> O(NlogN)\n\n\n Idea-> Create a dp arr which store | Java_Programmer_Ketan | NORMAL | 2022-09-11T04:01:04.059108+00:00 | 2022-09-11T04:01:57.077198+00:00 | 240 | false | ```\n/*\n This can be solved using a segment tree\n Time Complexity -> O(NlogN)\n Space Complexity -> O(NlogN)\n\n\n Idea-> Create a dp arr which stores the length of LIS ending at that index.\n Use maximum segment tree to get maximum in range and add 1, as this number is also a part of LIS\n*/\n... | 1 | 1 | [] | 0 |
longest-increasing-subsequence-ii | Segment Tree - [Point update, max in a range] || C++ | segment-tree-point-update-max-in-a-range-1qg9 | \nclass Solution {\nprivate:\n vector<int> tree;\n void pUpdate(int node,int st,int en,int pos,int val){\n if(st > pos or en < pos) return;\n\n | _Pinocchio | NORMAL | 2022-09-11T04:00:27.858036+00:00 | 2022-09-11T04:12:55.992840+00:00 | 395 | false | ```\nclass Solution {\nprivate:\n vector<int> tree;\n void pUpdate(int node,int st,int en,int pos,int val){\n if(st > pos or en < pos) return;\n\n if(st == en){\n tree[node] = max(tree[node],val);\n }else{\n int mid = st + (en - st)/2;\n pUpdate(node*2,st,mid,... | 1 | 1 | ['Tree', 'C', 'C++'] | 0 |
longest-increasing-subsequence-ii | Python | python-by-g-ez-4lm6 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G-EZ | NORMAL | 2025-03-14T00:00:59.890486+00:00 | 2025-03-14T00:00:59.890486+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:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python'] | 0 |
longest-increasing-subsequence-ii | Segment Tree | segment-tree-by-tavvfikk-5i16 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | tavvfikk | NORMAL | 2025-01-23T01:08:02.016444+00:00 | 2025-01-23T01:08:02.016444+00:00 | 31 | 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 | ['Segment Tree', 'C++'] | 0 |
longest-increasing-subsequence-ii | Simple Seg Tree | simple-seg-tree-by-rahulsaini1234-kbws | IntuitionMax range queries Segment Tree
Focus on values of nums[i].ApproachComplexity
Time complexity:
O(nlogn)
Space complexity:
O(n)Code | rahulsaini1234 | NORMAL | 2025-01-06T14:52:17.561234+00:00 | 2025-01-06T14:52:17.561234+00:00 | 12 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Max range queries Segment Tree
Focus on values of nums[i].
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(nlogn)
- Space complexi... | 0 | 0 | ['Java'] | 0 |
longest-increasing-subsequence-ii | Segment tree with point update | segment-tree-with-point-update-by-joshit-80wo | Code | joshithmurthy | NORMAL | 2025-01-04T18:33:27.136551+00:00 | 2025-01-04T18:33:27.136551+00:00 | 12 | false |
# Code
```cpp []
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
class Solution {
public:
void pointUpdate(vector<int>& tree, int node, int start, int end, int idx, int val) {
if (start == end) {
tree[node] = max(tree[node], val); // Update with max value
... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | C++ Segment Tree (Simple Code) | c-segment-tree-simple-code-by-yz19b-exzo | This is the hardest problem I've seen on Leetcode!Not only on dynamical programming, segment tree, but also on be clear about mananging index.IntuitionDynamical | yz19b | NORMAL | 2025-01-04T06:05:43.357604+00:00 | 2025-01-04T06:05:43.357604+00:00 | 19 | false | This is the hardest problem I've seen on Leetcode!
Not only on dynamical programming, segment tree, but also on be clear about mananging index.
# Intuition
### Dynamical Programming
Finding dynamical programming for this problem is not very hard:
Define: dp[i]: the length of longest subarray in the first i-1 element... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | Javascript Segment Tree O(n * log(max(n)) time, O(max(n)) space | javascript-segment-tree-on-logmaxn-time-fvdqr | IntuitionFor any value in nums, we can store the Longest Increasing Subsequence (LIS) ending at that value within a segment tree. As we iterate over nums, we ca | alexdovzhanyn | NORMAL | 2025-01-02T00:01:53.880601+00:00 | 2025-01-02T00:01:53.880601+00:00 | 4 | false | # Intuition
For any value in nums, we can store the Longest Increasing Subsequence (LIS) ending at that value within a segment tree. As we iterate over nums, we can efficiently find the maximum LIS of any numbers that the current nums[i] would be a valid next number for. This is any number in the range [n - k, n - 1], ... | 0 | 0 | ['Segment Tree', 'JavaScript'] | 0 |
longest-increasing-subsequence-ii | C++ Segment Tree | c-segment-tree-by-kimcuong09102004-5lcr | IntuitionApproachComplexity
Time complexity: O(nlogn)
Space complexity:
Code | kimcuong09102004 | NORMAL | 2024-12-14T10:10:45.106217+00:00 | 2024-12-14T10:10:45.106217+00:00 | 15 | 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: \n<!-- Add your space complexity here, ... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | Descriptive Explanation of DP to Segment Tree Optimization | descriptive-explanation-of-dp-to-segment-vwrx | null | diaalrahman312 | NORMAL | 2024-12-12T06:58:43.759599+00:00 | 2024-12-12T06:58:43.759599+00:00 | 25 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nRun the tabular approach first, and make sure to activate the print statement. This will help you visualise what\'s going on. The segment tree is just a handy data structure that helps in optimizing in range related questions. Use it inst... | 0 | 0 | ['Divide and Conquer', 'Dynamic Programming', 'Segment Tree', 'Python', 'Python3'] | 0 |
longest-increasing-subsequence-ii | GPT is really helpful | gpt-is-really-helpful-by-parthtiwari96-5qr0 | Intuition\nSolving it with segment tree was understood, since I had the same idea using the normal LCI problem.\n\n# Approach\nI asked GPT with very basic promp | parthtiwari96 | NORMAL | 2024-12-05T16:33:31.948471+00:00 | 2024-12-05T16:33:31.948513+00:00 | 24 | false | # Intuition\nSolving it with segment tree was understood, since I had the same idea using the normal LCI problem.\n\n# Approach\nI asked GPT with very basic prompt.\nPlease refer here.\nhttps://chatgpt.com/share/6751d421-5d68-8004-8242-aaa3b0aa9653\n<!-- Describe your approach to solving the problem. -->\n\n# Complexit... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | Classic Segment Tree - Max Value | classic-segment-tree-max-value-by-deydev-49gh | DP - Time Limit Exceeded\nPython []\nclass Solution:\n # O(n^2) time | O(n) space\n def lengthOfLIS(self, nums: List[int], k: int) -> int:\n n = le | deydev | NORMAL | 2024-11-30T10:48:10.867991+00:00 | 2024-11-30T10:52:29.037838+00:00 | 11 | false | # DP - Time Limit Exceeded\n``` Python []\nclass Solution:\n # O(n^2) time | O(n) space\n def lengthOfLIS(self, nums: List[int], k: int) -> int:\n n = len(nums)\n dp = [1] * n\n best_streak = 1\n\n for i in range(n):\n for j in range(i - 1, -1, -1):\n if 1 <= ... | 0 | 0 | ['Array', 'Dynamic Programming', 'Segment Tree', 'Python3'] | 0 |
longest-increasing-subsequence-ii | ✅ [JS/Rust] DP + Segment Tree Approach w/ explanation 🔥 | jsrust-dp-segment-tree-approach-w-explan-sgo1 | \uD83D\uDC4D If you found my solution to be beneficial, I would be most grateful if you would consider \u261D\uFE0FUPVOTING IT\u261D\uFE0F. This action would se | ad0x99 | NORMAL | 2024-11-20T12:23:41.496081+00:00 | 2024-11-20T12:23:41.496106+00:00 | 10 | false | **\uD83D\uDC4D If you found my solution to be beneficial, I would be most grateful if you would consider \u261D\uFE0FUPVOTING IT\u261D\uFE0F. This action would serve as a significant motivation for me to continue providing additional solutions in the future. \uD83D\uDE46\u200D\u2642\uFE0F**\n\n---\n\n# Dynamic Programm... | 0 | 0 | ['Dynamic Programming', 'Segment Tree', 'Rust', 'JavaScript'] | 0 |
longest-increasing-subsequence-ii | Longest Increasing Subsequence 2 | longest-increasing-subsequence-2-by-naee-j770 | 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 | Naeem_ABD | NORMAL | 2024-11-19T07:05:24.099456+00:00 | 2024-11-19T07:05:24.099493+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-increasing-subsequence-ii | Improved Segment Tree | C++ | solution | improved-segment-tree-c-solution-by-moha-hluk | Intuition\n###### take a look at the Solution here, I have optimized it in memory and speed, by calculating only the required space using max value each time an | mohamedsamir591195 | NORMAL | 2024-11-16T16:08:18.904131+00:00 | 2024-11-16T16:09:49.971479+00:00 | 19 | false | # Intuition\n###### take a look at the Solution [here](https://leetcode.com/problems/longest-increasing-subsequence-ii/solutions/2560010/c-segment-tree-with-illustrationexplanation/), I have optimized it in memory and speed, by calculating only the required space using max value each time and getting the power of two u... | 0 | 0 | ['Segment Tree', 'C++'] | 0 |
longest-increasing-subsequence-ii | [Java] Using SegmentTree | java-using-segmenttree-by-zanhd-8yn7 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nSegmentTree\n\n# Comple | zanhd | NORMAL | 2024-11-13T18:26:30.523053+00:00 | 2024-11-13T18:26:30.523078+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. -->\nSegmentTree\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(4 * max-number)\n<!-- Add ... | 0 | 0 | ['Divide and Conquer', 'Segment Tree', 'Java'] | 0 |
longest-increasing-subsequence-ii | C++, O(n*log(10^5)) | c-onlog105-by-samaun37-tuzd | 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 | samaun37 | NORMAL | 2024-10-29T18:10:04.719046+00:00 | 2024-10-29T18:10:04.719069+00:00 | 18 | 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-increasing-subsequence-ii | Minimal Code, Maximal Comments, Beats 100% | minimal-code-maximal-comments-beats-100-kjak5 | Intuition\nMultiple brute force methods require repeatedly getting the max of n or k values, and they all exceed the time limit. We can get the max of a bunch o | kitfo | NORMAL | 2024-10-27T19:51:05.530380+00:00 | 2024-10-27T19:51:05.530462+00:00 | 10 | false | # Intuition\nMultiple brute force methods require repeatedly getting the max of n or k values, and they all exceed the time limit. We can get the max of a bunch of elements more efficiently if we store them in a segment tree.\n\n# Approach\nI had a couple failed approaches. The first was to walk nums backwards. For eac... | 0 | 0 | ['Python3'] | 0 |
longest-increasing-subsequence-ii | Dynamic Programming || AVS | dynamic-programming-avs-by-vishal1431-odzk | \n# Code\ncpp []\nclass Solution {\npublic:\n int n;\n vector<int> segtree;\n \n int BestRange(int start, int end) {\n int res = 0;\n | Vishal1431 | NORMAL | 2024-10-19T12:58:45.183955+00:00 | 2024-10-19T12:58:45.183999+00:00 | 41 | false | \n# Code\n```cpp []\nclass Solution {\npublic:\n int n;\n vector<int> segtree;\n \n int BestRange(int start, int end) {\n int res = 0;\n start += 1e5 - 1;\n end += 1e5 - 1;\n \n while (start < end) {\n res = max({segtree[start], segtree[end], res});\n ... | 0 | 0 | ['Dynamic Programming', 'Segment Tree', 'C++'] | 0 |
longest-increasing-subsequence-ii | Longest increasing subsequence ii | longest-increasing-subsequence-ii-by-nit-e63d | 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 | Nityananadh | NORMAL | 2024-10-12T04:29:33.880051+00:00 | 2024-10-12T04:29:33.880086+00:00 | 19 | 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-increasing-subsequence-ii | Go Segment Tree | go-segment-tree-by-german_gorelkin-3n3x | \n\n# Code\ngolang []\nfunc lengthOfLIS(nums []int, k int) int {\n\tst := NewSegmentTree(nums)\n\n\tfor _, n := range nums {\n\t\tn--\n\t\tl := max(0, n-k)\n\t\ | german_gorelkin | NORMAL | 2024-10-03T08:29:47.754513+00:00 | 2024-10-03T08:29:47.754534+00:00 | 2 | false | \n\n# Code\n```golang []\nfunc lengthOfLIS(nums []int, k int) int {\n\tst := NewSegmentTree(nums)\n\n\tfor _, n := range nums {\n\t\tn--\n\t\tl := max(0, n-k)\n\t\tlmax := st.query(l, n-1, 0, st.n-1, 0)\n\t\tlmax++\n\t\tst.update(n, lmax, 0, st.n-1, 0)\n\t}\n\n\treturn st.maxVal()\n}\n\nfunc maxVal(nums []int) int {\n\... | 0 | 0 | ['Segment Tree', 'Go'] | 0 |
longest-increasing-subsequence-ii | DP w/ Segment Tree | dp-w-segment-tree-by-anastasiskolio13-wz13 | 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 | anastasiskolio13 | NORMAL | 2024-09-30T04:08:56.214907+00:00 | 2024-09-30T04:10:35.724729+00:00 | 26 | 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$$\\mathcal{O}(N \\cdot \\text{log } (\\max_{0 \\leq i \\leq N - 1}\\{A[i]\\} + K))$$\n\n- Space complexity:\n$$\\mathcal{O}(N + \\... | 0 | 0 | ['Dynamic Programming', 'Segment Tree', 'C++'] | 0 |
longest-increasing-subsequence-ii | longest-increasing-subsequence-ii - Java Solution | longest-increasing-subsequence-ii-java-s-blid | \n# Code\njava []\nclass Solution {\n class Node{\n int val;\n Node left;\n Node right;\n int start;\n int end;\n }\n | himashusharma | NORMAL | 2024-09-25T07:40:27.426633+00:00 | 2024-09-25T07:40:27.426677+00:00 | 18 | false | \n# Code\n```java []\nclass Solution {\n class Node{\n int val;\n Node left;\n Node right;\n int start;\n int end;\n }\n public int lengthOfLIS(int[] nums, int k) {\n int max = 0;\n for(int num : nums){\n max = Math.max(max,num);\n }\n \... | 0 | 0 | ['Java'] | 0 |
longest-increasing-subsequence-ii | Golang segment tree | golang-segment-tree-by-alishagupta262-swga | 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 | alishagupta262 | NORMAL | 2024-09-07T10:08:21.418920+00:00 | 2024-09-07T10:08:21.418951+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 | ['Go'] | 0 |
longest-increasing-subsequence-ii | 3 liner Logic for a Segment Tree Solution || Explained | 3-liner-logic-for-a-segment-tree-solutio-iaey | Complexity\n- Time complexity: O(n*log(n)) \n\n- Space complexity: O(n) \n\n# Code\ncpp []\nclass SegmentTree\n{\n int len;\n vector<int> seg;\n\n void comb | coder_rastogi_21 | NORMAL | 2024-08-30T19:00:36.308398+00:00 | 2024-08-30T19:00:36.308422+00:00 | 15 | false | # Complexity\n- Time complexity: $$O(n*log(n))$$ \n\n- Space complexity: $$O(n)$$ \n\n# Code\n```cpp []\nclass SegmentTree\n{\n int len;\n vector<int> seg;\n\n void combine(int ind) { \n\t\t seg[ind] = max(seg[2*ind+1],seg[2*ind+2]); \n\t }\n\n int query(int ind, int low, int high, int l, int r)\n {\n i... | 0 | 0 | ['Segment Tree', 'C++'] | 0 |
longest-increasing-subsequence-ii | 2407. Longest Increasing Subsequence II | 2407-longest-increasing-subsequence-ii-b-za0o | Intuition\n Describe your first thoughts on how to solve this problem. \nUse segment Trees to find max(dp[j]) such that j < nums[i] && j <= nums[i] - k \n\n# Ap | avneeshpathak93 | NORMAL | 2024-08-19T05:52:16.095691+00:00 | 2024-08-19T05:52:16.095739+00:00 | 46 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse segment Trees to find max(dp[j]) such that j < nums[i] && j <= nums[i] - k \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can optimize query using segment Trees.\n\n# Complexity\n- Time complexity:\n<!-- A... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | Longest Increasing Subsequence 2 | longest-increasing-subsequence-2-by-tome-c3x2 | Intuition\n Describe your first thoughts on how to solve this problem. \nSegment Tree\n# Approach\n Describe your approach to solving the problem. \nSegment Tre | tomerdrr | NORMAL | 2024-07-21T09:55:27.660573+00:00 | 2024-07-21T09:55:27.660618+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSegment Tree\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSegment Tree\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*k)\n- Space complexity:\n<!-- Add your space com... | 0 | 0 | ['Python'] | 0 |
longest-increasing-subsequence-ii | Python (Simple Segment Tree) | python-simple-segment-tree-by-rnotappl-lyxp | 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-07-20T09:55:57.225569+00:00 | 2024-07-20T09:55:57.225596+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 | ['Python3'] | 0 |
longest-increasing-subsequence-ii | Python (Simple DP) | python-simple-dp-by-rnotappl-7nad | 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-07-19T16:56:39.556748+00:00 | 2024-07-19T16:56:39.556777+00:00 | 32 | 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-increasing-subsequence-ii | Not a fully passed solution, but the code is short. 80/84 passed. Any good idea to pass it? | not-a-fully-passed-solution-but-the-code-3zv1 | Intuition\nI am using the TreeMap (Segment Tree), array item value as key, the length of the longest subsequence ending with it as the value.\n\n\n# Approach\n\ | qiuping345 | NORMAL | 2024-07-11T07:01:35.281576+00:00 | 2024-07-11T07:01:35.281599+00:00 | 17 | false | # Intuition\nI am using the TreeMap (Segment Tree), array item value as key, the length of the longest subsequence ending with it as the value.\n\n\n# Approach\n\n\n# Complexity\n- Time complexity:\nTypically O(n*lg(n)), worst case O(n^2)\n\nI passed 80 test cases out of the 84. Failed on the worst cases, that are incr... | 0 | 0 | ['Java'] | 0 |
longest-increasing-subsequence-ii | My take on this Problem | my-take-on-this-problem-by-amit130-8ode | 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 | Amit130 | NORMAL | 2024-07-11T06:16:13.205750+00:00 | 2024-07-11T06:16:13.205788+00:00 | 124 | 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 log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, ... | 0 | 0 | ['Array', 'Divide and Conquer', 'Dynamic Programming', 'Binary Indexed Tree', 'Segment Tree', 'Monotonic Stack', 'C++'] | 0 |
longest-increasing-subsequence-ii | My take on this Problem | my-take-on-this-problem-by-amit130-ked9 | 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 | Amit130 | NORMAL | 2024-07-11T06:16:04.564009+00:00 | 2024-07-11T06:16:04.564036+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: 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, ... | 0 | 0 | ['Segment Tree', 'Monotonic Stack'] | 0 |
longest-increasing-subsequence-ii | [Segment Tree] Intuition + Explanation | segment-tree-intuition-explanation-by-an-bjoa | Intuition\nSegment Tree would help noting the longest known subsequence for any last number between [l, r]\n\n# Approach\n- For each i, query the longest known | anushree97 | NORMAL | 2024-07-08T17:14:52.001983+00:00 | 2024-07-08T17:14:52.002016+00:00 | 20 | false | # Intuition\nSegment Tree would help noting the longest known subsequence for any last number between [l, r]\n\n# Approach\n- For each i, query the longest known subsequence whose last number is between range [max(i-k), i-1]\n- Now add 1 to above query and update it in vertex of (i)\n- Each vertex would store longest s... | 0 | 0 | ['Segment Tree', 'Python3'] | 0 |
longest-increasing-subsequence-ii | ap | ap-by-ap5123-uvbv | 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 | ap5123 | NORMAL | 2024-07-06T13:14:57.360446+00:00 | 2024-07-06T13:14:57.360483+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-increasing-subsequence-ii | Solution | solution-by-penrosecat-9nhd | Intuition\n Describe your first thoughts on how to solve this problem. \nThe underlying array of the segment tree represents the length of LIS ending with nums[ | penrosecat | NORMAL | 2024-07-05T07:16:33.202693+00:00 | 2024-07-05T07:16:33.202713+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe underlying array of the segment tree represents the length of LIS ending with nums[i] in the array from 1 to max(nums[i]).\n\nNow, for an element nums[i], we have to get (range query) the max length of LIS from nums[i]-k to nums[i]-1 ... | 0 | 0 | ['C++'] | 0 |
longest-increasing-subsequence-ii | LIS + Segment tree | lis-segment-tree-by-laithy_uchiha-lni5 | 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 | Laithy_uchiha | NORMAL | 2024-07-02T16:00:14.520985+00:00 | 2024-07-02T16:00:14.521084+00:00 | 33 | 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 |
string-transformation | 【C++ || Java || Python】 Short Code by Finding the Pattern | c-java-python-short-code-by-finding-the-px422 | I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.\n\n> In addition, I\'m too weak, please be critical of m | RealFan | NORMAL | 2023-09-10T04:05:18.991287+00:00 | 2024-01-14T03:57:12.972032+00:00 | 8,017 | false | > **I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.**\n\n> **In addition, I\'m too weak, please be critical of my ideas.**\n---\n\n# Brief Solution\n**Rolling will change the beginning index of $$s$$. So enumerate each index as the beginning index, count the numbe... | 51 | 0 | ['Math', 'String Matching', 'C++', 'Java', 'Python3'] | 10 |
string-transformation | Solutions with C++, Java and python | solutions-with-c-java-and-python-by-cpcs-6u26 | Intuition\nDP, Z-algorithm, Fast mod.\n\n# Approach\n1. How to represent a string?\nEach operation is just a rotation. Each result string can be represented by | cpcs | NORMAL | 2023-09-10T04:01:59.733285+00:00 | 2023-09-10T04:01:59.733315+00:00 | 8,264 | false | # Intuition\nDP, Z-algorithm, Fast mod.\n\n# Approach\n1. How to represent a string?\nEach operation is just a rotation. Each result string can be represented by an integer from 0 to n - 1. Namely, it\'s just the new index of s[0].\n\n2. How to find the integer(s) that can represent string t?\nCreate a new string s + t... | 41 | 0 | ['Python', 'C++', 'Java', 'Python3'] | 8 |
string-transformation | Rabin-Karp and Recurrence Relation | rabin-karp-and-recurrence-relation-by-je-ujrd | Intuition\nClearly, t must be some rotation of s. Moreover, we see that if t is s rotated by some amount i, the problem essentially asks how many ways we can su | jeffreyhu8 | NORMAL | 2023-09-10T04:01:29.811268+00:00 | 2023-09-13T16:25:02.291855+00:00 | 2,351 | false | # Intuition\nClearly, `t` must be some rotation of `s`. Moreover, we see that if `t` is `s` rotated by some amount `i`, the problem essentially asks how many ways we can sum up `k` integers in `[1, n)` that add up to `i` modulo `n`, which is a type of dynamic programming problem. The problem reduces to\n1. Finding whic... | 26 | 0 | ['String', 'Python3'] | 4 |
string-transformation | Java Solution With Detailed Explanation | java-solution-with-detailed-explanation-pst4o | Background\n\nRemoving the suffix of length l and appending to the front is same as a right shift. So after k operations. S would just be right shifted some num | profchi | NORMAL | 2023-09-10T04:02:17.348402+00:00 | 2023-09-13T04:03:24.608050+00:00 | 2,480 | false | # Background\n\nRemoving the suffix of length l and appending to the front is same as a right shift. So after k operations. S would just be right shifted some number of times.\n\n# Solution\n\nFirst ignore the constraint for k and n. Let n be the length of s. We can solve this easily with a 2 dimensional dp[kTimes][shi... | 18 | 0 | ['Rolling Hash', 'Matrix', 'Java'] | 3 |
string-transformation | 😵💫Complex Maths || Derivation || Z-Algo || | complex-maths-derivation-z-algo-by-jainw-dned | Sorry for such messy mathematics , \n### But it is what it is !!\n\n\n\n# Code\n\n#define ll long long\nclass Solution {\npublic:\n int mod=1e9+7;\n\n ll | JainWinn | NORMAL | 2023-09-10T18:40:33.505544+00:00 | 2023-09-10T18:42:00.192610+00:00 | 667 | false | #### Sorry for such messy mathematics , \n### But it is what it is !!\n\n\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n int mod=1e9+7;\n\n ll calcpower(ll x, ll n)\n {\n ... | 10 | 0 | ['Math', 'String Matching', 'C++'] | 2 |
string-transformation | Patterns, KMP and maths | python No matrix exponentiation | Explanation of modular arithmetic | patterns-kmp-and-maths-python-no-matrix-ip7rv | Approach\nFirst, let\'s define the possible rotations of $s$ in which $s_i = t$, with $s_i$ being $s$ rotated $i$ to the left. We can obtain all the possible ro | BetoSCL | NORMAL | 2023-09-10T04:10:20.295160+00:00 | 2023-09-10T22:34:46.946637+00:00 | 1,208 | false | # Approach\nFirst, let\'s define the possible rotations of $s$ in which $s_i = t$, with $s_i$ being $s$ rotated $i$ to the left. We can obtain all the possible rotations using the Knuth-Morris-Pratt (KMP) algorithm. By doubling the string $s$ and finding all occurrences of $t$, we identify these rotations.\n\nAfter pre... | 9 | 0 | ['Python3'] | 2 |
string-transformation | [QUICK MAFS] The math explained REAL simply | quick-mafs-the-math-explained-real-simpl-kmiz | Intuition\nSo first off, as noted in many other solutions, this fancy schmancy operation is equivalent to rotating the string by a certain amount $\color{pink}i | gtsmarmy | NORMAL | 2023-09-13T01:53:49.674686+00:00 | 2023-09-13T02:00:07.895090+00:00 | 537 | false | # Intuition\nSo first off, as noted in many other solutions, this fancy schmancy operation is equivalent to rotating the string by a certain amount $\\color{pink}i$. What\'s nice about framing it in this manner is that you can associate every rotated string (there are $\\color{lime} n-1$ of them) with an integer $\\col... | 8 | 0 | ['Math', 'Recursion', 'C++'] | 4 |
string-transformation | Python solution, O(n), string hash + combinatorics | python-solution-on-string-hash-combinato-6c9x | The question consists of two parts:\n\n1. String matching. Find all 0 < r < n, so that after an r-rotation from s, s is the same as t.\n2. Combinatorics. For an | Maruzensky | NORMAL | 2023-09-10T04:00:58.812543+00:00 | 2023-09-11T17:40:40.896595+00:00 | 979 | false | The question consists of two parts:\n\n1. String matching. Find all 0 < r < n, so that after an r-rotation from s, s is the same as t.\n2. Combinatorics. For an r in step 1, count the number of x_1, ..., x_k, so that for each x_i, 0 < x_i < n and x_1 + ... + x_k = r (mod n).\n\nFor part 1, we will do string hash. Basic... | 8 | 0 | [] | 1 |
string-transformation | String Matching || Dynamic Programming || Matrix Exponential || C++ | string-matching-dynamic-programming-matr-94wi | \n# Approach\n- We can make string t from string s in minimum one step and if it doesn\'t then we can\'t make it to string t.\n- Let, move to the dp solution fo | Syphenlm12 | NORMAL | 2023-09-10T14:40:09.882184+00:00 | 2023-09-10T14:40:09.882214+00:00 | 802 | false | \n# Approach\n- We can make string t from string s in minimum one step and if it doesn\'t then we can\'t make it to string t.\n- Let, move to the dp solution for this question.\n- dp[1][i] represent that on the ith step we can our string to be equal to string t its number of ways to make it.\n- dp[0][i] represent that ... | 7 | 0 | ['Dynamic Programming', 'Rolling Hash', 'String Matching', 'Matrix', 'C++'] | 2 |
string-transformation | Complete guide covering all topics with links from where to study || Brute Force->optimal | complete-guide-covering-all-topics-with-q583b | Hey folks don't give up.IntuitionWe only have to return the number of ways in which s can be transformed into t in exactly k operations. Whenever such type of s | Ayush-Rawat | NORMAL | 2025-01-11T17:15:56.226268+00:00 | 2025-01-12T06:19:53.941256+00:00 | 625 | false | `Hey folks don't give up.`
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We only have to return the number of ways in which s can be transformed into t in exactly k operations. Whenever such type of string question comes don't think of actually transforming the string.
Without transfor... | 6 | 0 | ['Math', 'String', 'Dynamic Programming', 'Recursion', 'String Matching', 'Matrix', 'Java', 'Python3'] | 0 |
string-transformation | ✅ [Python] Short and Explained || 100% Faster || Sum of Geometric Series | python-short-and-explained-100-faster-su-iz5w | Please UPVOTE if you LIKE! \uD83D\uDE01\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n r denotes the number of times that string | linfq | NORMAL | 2023-11-06T08:40:29.789086+00:00 | 2023-11-06T08:47:41.142788+00:00 | 714 | false | **Please UPVOTE if you LIKE!** \uD83D\uDE01\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* r denotes the number of times that string s obtains itself through rotation 0 <= l < n. Obviously r is at least 1, when l == 0.\n\n - It means if s can be transformed into t and s != t, ... | 6 | 0 | ['Python', 'Python3'] | 0 |
string-transformation | I got KMP and matrix multiply code from ChatGPT.. | i-got-kmp-and-matrix-multiply-code-from-vnnb6 | Intuition\nYou can see it\'s DP, and need KMP and matrix multiply to improve performace.\n\nWhen coding the solution, I got KMP and matrix multiply code from Ch | suiyuan1992 | NORMAL | 2023-09-10T04:16:33.071570+00:00 | 2023-09-10T04:16:33.071589+00:00 | 1,272 | false | # Intuition\nYou can see it\'s DP, and need KMP and matrix multiply to improve performace.\n\nWhen coding the solution, I got KMP and matrix multiply code from ChatGPT..\n\n# Code\n```\nclass Solution {\nprivate:\nstd::vector<int> buildKMPTable(const std::string& pattern) {\n int m = pattern.length();\n std::vect... | 5 | 0 | ['C++'] | 1 |
string-transformation | [C++] Using string::find is (in fact NOT) efficient enough | c-using-stringfind-is-in-fact-not-effici-n8d5 | [EDIT] Thanks to @lyronly, string::find costs O(N^2) and will not make it if extreme testcases are provided, such as:\n\ns="a"*499999+"b"\nt="a"*500000\n\n\n--- | orthogonal1 | NORMAL | 2023-09-10T10:02:15.373775+00:00 | 2023-09-11T08:58:23.105235+00:00 | 367 | false | [EDIT] Thanks to @lyronly, string::find costs O(N^2) and will not make it if extreme testcases are provided, such as:\n```\ns="a"*499999+"b"\nt="a"*500000\n```\n\n------------------\n\nI\'m surprised that string::find is efficient enough but there\'s no solutions posted here using it so far. I won\'t explain the math t... | 4 | 0 | ['C++'] | 2 |
string-transformation | [Java] 37ms Math solution without DP | java-37ms-math-solution-without-dp-by-wd-i82s | Intuition\n\nThe solution is kinda cheating a little bit. But nevertheless, it is insane to have such a hard question in Leetcode. \n\nIdea: \n\nThe quesiton ba | wddd | NORMAL | 2023-09-10T06:10:15.232519+00:00 | 2024-05-30T01:37:43.540398+00:00 | 998 | false | # Intuition\n\nThe solution is kinda cheating a little bit. But nevertheless, it is insane to have such a hard question in Leetcode. \n\nIdea: \n\nThe quesiton basically asks \n1. After `k` times of rotation (each rotation takes `l (0 < l < n)` step), the counts of each unique ending strings. \n1. Then sum the total co... | 3 | 0 | ['Math', 'Rolling Hash', 'Java'] | 3 |
string-transformation | Three Steps: string match, recursion and speed up | three-steps-string-match-recursion-and-s-eapu | To solve this problem, you need to know:\n1 O(n) string match algorithm (I use z function as an example here):\nhttps://cp-algorithms.com/string/z-function.html | gaoyf1235 | NORMAL | 2023-09-10T05:17:43.829716+00:00 | 2023-09-10T05:47:17.513483+00:00 | 788 | false | To solve this problem, you need to know:\n1 O(n) string match algorithm (I use z function as an example here):\nhttps://cp-algorithms.com/string/z-function.html\n2 Fast modular inverse algorithm:\nhttps://cp-algorithms.com/algebra/binary-exp.html\nhttps://cp-algorithms.com/algebra/module-inverse.html\n\nThen the three ... | 3 | 0 | ['C'] | 0 |
string-transformation | [Python] Cheating with built-in find | python-cheating-with-built-in-find-by-re-e4vt | Finish this solution after the contest. :( \nCheating on some special cases. Using find is enough.\nres represents the number of ways by rotating s to get it se | Remineva | NORMAL | 2023-09-10T04:40:01.978320+00:00 | 2023-09-12T20:25:20.264282+00:00 | 1,722 | false | Finish this solution after the contest. :( \nCheating on some special cases. Using `find` is enough.\n`res` represents the number of ways by rotating `s` to get it self. Let `f_k` be the solution for `k` operations. Then we have `f_{k+1} = [(n-1)^k - f_k] * res + f_k * (res - 1)`, which gives us `f_k = (-1)^k * (f_0 - ... | 3 | 0 | ['Python'] | 1 |
string-transformation | [Python] - linear algebra + KMP O(log(k)+n) | python-linear-algebra-kmp-ologkn-by-knat-kpg0 | Sorry for my bad handwriting >.<\n\n\n\n\n\n\n\n\n\n# Code\n\nclass Solution:\n def compute_lps_array(self, pattern):\n length = 0\n lps = [0] | knatti | NORMAL | 2024-01-31T13:51:08.263483+00:00 | 2024-02-07T08:29:56.925779+00:00 | 473 | false | **Sorry for my bad handwriting >.<**\n\n\n\n\n\n$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Java'] | 0 |
string-transformation | O(n), no DP | on-no-dp-by-pvillano-ff03 | Intuition\nImportant observations:\n- Removing a suffix of s and appending it at the start of s is a rotation.\n- Using one rotation, s can be rotated to t in m | pvillano | NORMAL | 2023-09-11T21:51:33.078579+00:00 | 2023-09-11T21:51:33.078609+00:00 | 617 | false | # Intuition\nImportant observations:\n- Removing a suffix of s and appending it at the start of s is a rotation.\n- Using one rotation, s can be rotated to t in multiple ways only if s repeats.\n- The number of solutions "should" only depend on k and how many times s repeats (and if one exists)\n - However, the exclus... | 2 | 0 | ['Python3'] | 1 |
string-transformation | My solution (String Hashing + math) with external links to foundation knowledge | my-solution-string-hashing-math-with-ext-pkx3 | Reason of sharing solution\n Describe your first thoughts on how to solve this problem. \nI am shocked that leetcode contest have such problem that required hig | marvenlee | NORMAL | 2023-09-11T21:41:26.857226+00:00 | 2023-09-11T21:41:26.857257+00:00 | 99 | false | # Reason of sharing solution\n<!-- Describe your first thoughts on how to solve this problem. -->\nI am shocked that leetcode contest have such problem that required high math skill. Therefore, I am writing this solution with some of my suggested link to learn the foundation. Hopefully this solution would help people w... | 2 | 0 | ['Math', 'Rolling Hash', 'Matrix', 'C++'] | 0 |
string-transformation | Python3 | Super Short Solution - O(n + logk) | Math + KMP | python3-super-short-solution-on-logk-mat-oefq | Intuition\nOperation = rotation, but no identical rotation\nTherefore, there are\n $f(k)$ combinations to get any $rotation \neq s$\n $f\prime(k) = (n-1) \cdot | deimvis | NORMAL | 2023-09-10T22:32:21.913831+00:00 | 2023-09-10T22:33:31.212856+00:00 | 1,981 | false | # Intuition\nOperation = rotation, but no identical rotation\nTherefore, there are\n* $f(k)$ combinations to get any $rotation \\neq s$\n* $f\\prime(k) = (n-1) \\cdot f(k-1)$ combinations to get $rotation = s$\n\n# Approach = Math + KMP\n* $f(k) = \\frac{(n-1)^k - (-1)^k}{n}$ (similarly as in the [video](https://www.yo... | 2 | 0 | ['Python3'] | 0 |
string-transformation | Rabin-Karp Rolling Hash + Math in Python with Explanation | rabin-karp-rolling-hash-math-in-python-w-wc3x | Approach\n Describe your first thoughts on how to solve this problem. \nFirst we need to find the number of answer positions i that make s[i:i+n] == t. Any effi | metaphysicalist | NORMAL | 2023-12-21T16:50:03.035311+00:00 | 2023-12-21T16:50:03.035342+00:00 | 81 | false | # Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst we need to find the number of <b>answer</b> positions `i` that make `s[i:i+n] == t`. Any efficient string matching can be applied. My solution employs the Rabin-Karp rolling hash for string matching. \n\nThen, a little math is used t... | 1 | 0 | ['Math', 'Divide and Conquer', 'Rolling Hash', 'String Matching', 'Python3'] | 0 |
string-transformation | Notes showing steps to come up to a solution | Matrix Exponentiation | KMP | notes-showing-steps-to-come-up-to-a-solu-ls1b | Intuition\nIt took me a while to figure out the solution and there are excellent solutions posted by other experienced people.\nThe note shows the process I too | cold_coffee | NORMAL | 2023-09-15T05:23:42.029307+00:00 | 2023-09-15T05:23:42.029336+00:00 | 115 | false | # Intuition\nIt took me a while to figure out the solution and there are excellent solutions posted by other experienced people.\nThe note shows the process I took to finally come to the solution.\n\n# Approach\n, O(n + log(k)), beats 100% | python-analytical-insights-math-on-logk-w6e72 | Intuition\n1. Observation #1\nRegardless how many times we do operation we always end up in some "sufix-to-pref" position (more formally s->s[i:]+s[:i]). Which | raggzy | NORMAL | 2023-09-11T02:52:56.390570+00:00 | 2023-09-11T03:19:51.962016+00:00 | 93 | false | # Intuition\n1. Observation #1\nRegardless how many times we do operation we always end up in some "sufix-to-pref" position (more formally `s->s[i:]+s[:i]`). Which means end strings differ only in that "split" position (`i`). So we kind of want to track how many ways would end in each position.\n2. Observation #2\nIf s... | 1 | 0 | ['Python3'] | 0 |
string-transformation | Efficient Cyclical Pattern Matching: A Novel KMP Approach with Dynamic Frequency Calculation | efficient-cyclical-pattern-matching-a-no-19wx | Intuition\nWhen presented with the problem of finding the number of ways two strings can match based on a given pattern, my initial instinct was to use the Knut | janis__ | NORMAL | 2023-09-10T11:09:17.739156+00:00 | 2023-09-10T11:09:17.739174+00:00 | 96 | false | # Intuition\nWhen presented with the problem of finding the number of ways two strings can match based on a given pattern, my initial instinct was to use the Knuth-Morris-Pratt (KMP) algorithm. The KMP algorithm is a powerful tool for pattern searching and can identify all occurrences of a pattern in a text in linear t... | 1 | 1 | ['Python3'] | 0 |
string-transformation | [Java] KMP + Matrix QuickPow, O(n + logk), 54ms | java-kmp-matrix-quickpow-on-logk-54ms-by-einy | \nclass Solution {\n // time = O(n + logk), space = O(n)\n final int mod = (int)1e9 + 7;\n long[][] g;\n public int numberOfWays(String s, String t, | silentwings | NORMAL | 2023-09-10T06:51:53.967406+00:00 | 2024-02-02T08:36:19.684375+00:00 | 505 | false | ```\nclass Solution {\n // time = O(n + logk), space = O(n)\n final int mod = (int)1e9 + 7;\n long[][] g;\n public int numberOfWays(String s, String t, long k) {\n int n = s.length();\n int v = kmp(s + s, t);\n g = new long[][]{{v - 1, v}, {n - v, n - 1 - v}};\n long[][] f = qmi(... | 1 | 0 | ['Java'] | 1 |
string-transformation | Matrix Exp. + Z-Algo | matrix-exp-z-algo-by-dnitin28-ax5p | \n# Code\n\nclass Solution {\npublic:\n const int mod = 1e9 + 7;\n vector<int> zAlgo(string s){\n int n = s.size();\n vector<int> Z(n);\n | gyrFalcon__ | NORMAL | 2023-09-10T06:13:33.280695+00:00 | 2023-09-10T06:13:33.280729+00:00 | 259 | false | \n# Code\n```\nclass Solution {\npublic:\n const int mod = 1e9 + 7;\n vector<int> zAlgo(string s){\n int n = s.size();\n vector<int> Z(n);\n int l = 0, r = 0;\n for(int i=1;i<n;i++){\n if(i <= r){\n Z[i] = min(Z[i-l], r-i+1);\n }\n while(... | 1 | 0 | ['C++'] | 0 |
string-transformation | Python solution | python-solution-by-vilmos_prokaj-16cq | Intuition\nSimilar to other solutions. It finds the matches, then computes the number of possibilities for each possible match. For matrix exponentiation it use | vilmos_prokaj | NORMAL | 2023-09-10T05:45:51.948649+00:00 | 2023-09-10T05:45:51.948667+00:00 | 930 | false | # Intuition\nSimilar to other solutions. It finds the matches, then computes the number of possibilities for each possible match. For matrix exponentiation it uses that \n$$\n A=\\begin{pmatrix}\nn-2 & n-1\\\\ 1 & 0\n\\end{pmatrix}\n$$\nthe characteristic polynomial is $A^2-(n-1)A-(n-2)I=0$. The power is returned in... | 1 | 0 | ['Python3'] | 0 |
string-transformation | Java Solution with explanation - beats 97% of submissions | java-solution-with-explanation-beats-97-2vcse | IntuitionRemoving the suffix of the string and putting it in the front is nothing but string rotation.Ideally, create string s + s and finding all count's of st | kodekrafter | NORMAL | 2025-02-28T16:39:45.984688+00:00 | 2025-02-28T16:39:45.984688+00:00 | 36 | false | # Intuition
Removing the suffix of the string and putting it in the front is nothing but string rotation.
Ideally, create string `s` + `s` and finding all `count`'s of string `t` would give how many occurences of `t` are possible when applying rotations to string `s`.
Once this is done, there are state transitions th... | 0 | 0 | ['Java', 'Python3'] | 0 |
string-transformation | ◈ Python ◈ String Matching ◈ Math ◈ DP ◈ KMP | python-string-matching-math-dp-kmp-by-zu-p2hl | Glossary:
s: The original string.
t: The target string to transform s into.
k: The maximum number of allowed rotations.
N: The length of the strings s and t.
MO | zurcalled_suruat | NORMAL | 2025-02-17T19:01:33.125834+00:00 | 2025-02-17T19:01:33.125834+00:00 | 30 | false | ### Glossary:
- $s$: The original string.
- $t$: The target string to transform $s$ into.
- $k$: The maximum number of allowed rotations.
- $N$: The length of the strings $s$ and $t$.
- $MOD$: The modulus for calculations, equal to $10^9 + 7$.
- $dp[i_{turn}][n_{rotation}]$: The number of ways to reach a state of $n_{... | 0 | 0 | ['Math', 'Dynamic Programming', 'String Matching', 'Python3'] | 0 |
string-transformation | Explained Clean Code | 10ms beats 100% | explained-clean-code-10ms-beats-100-by-i-io3n | IntuitionThis problem reduces to finding cyclic patterns in strings and efficiently calculating the number of ways to reach specific positions through k shifts | ivangnilomedov | NORMAL | 2025-02-08T20:17:26.062093+00:00 | 2025-02-08T20:17:26.062093+00:00 | 26 | false | # Intuition
This problem reduces to finding cyclic patterns in strings and efficiently calculating the number of ways to reach specific positions through k shifts using matrix exponentiation.
# Approach
The solution works in three key stages:
1. First, we find if and where string t appears as a cyclic shift of s. Thi... | 0 | 0 | ['C++'] | 0 |
string-transformation | 💥💥 Beats 100% on runtime and memory [EXPLAINED] | beats-100-on-runtime-and-memory-explaine-08h0 | IntuitionFind how many different ways you can select a subsequence of string t from string s and count the number of ways it can occur for k times, using matrix | r9n | NORMAL | 2025-01-11T08:19:30.683133+00:00 | 2025-01-11T08:19:30.683133+00:00 | 23 | false | # Intuition
Find how many different ways you can select a subsequence of string t from string s and count the number of ways it can occur for k times, using matrix exponentiation and hash functions.
# Approach
I used a rolling hash technique to efficiently compare substrings of s with t, storing the matching positions... | 0 | 0 | ['Math', 'String', 'Divide and Conquer', 'Dynamic Programming', 'Recursion', 'Rolling Hash', 'String Matching', 'Matrix', 'C#'] | 0 |
string-transformation | Python Hard | python-hard-by-lucasschnee-3a29 | null | lucasschnee | NORMAL | 2025-01-07T00:31:28.009043+00:00 | 2025-01-07T00:31:28.009043+00:00 | 22 | false | ```python3 []
class Solution:
def numberOfWays(self, s: str, t: str, k: int) -> int:
'''
its just a rotating string
so, first find number of ways that s rotated is t
then, we can make N - 1 moves every turn, and 1 move the last turn
exactly k operations
N - 1 then... | 0 | 0 | ['Python3'] | 0 |
string-transformation | String Matching + Maths | string-matching-maths-by-up41guy-k2lo | TC: O(N + logK)
SC : O(N) | Cx1z0 | NORMAL | 2024-12-26T11:24:27.374397+00:00 | 2024-12-26T11:30:03.732484+00:00 | 25 | false | TC: O(N + logK)
SC : O(N)
---
```javascript []
function numberOfWays(s, t, k) {
const MOD = 1e9 + 7;
const n = s.length;
if (!s || !t || k < 0) return 0;
// Create circular string once
const ss = s + s;
const first = ss.indexOf(t);
if (first === -1) return 0;
const zero_targets = first === 0 ? 1 :... | 0 | 0 | ['Math', 'String', 'String Matching', 'JavaScript'] | 0 |
string-transformation | 7ms Python solution (top 5%) with extensive comments and explanation behind the mathematics | 7ms-python-solution-top-5-with-extensive-fv6u | Intuition\n Describe your first thoughts on how to solve this problem. \nIn general, you can see the source string $s$ and target string $t$ as two circular str | NicolasHeintz | NORMAL | 2024-11-26T18:48:48.327579+00:00 | 2024-11-26T18:48:48.327614+00:00 | 27 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn general, you can see the source string $s$ and target string $t$ as two circular strings. The only possible transformation is a rotation of that string. At each operation, you can rotate the string with any amount $[1,L-1]$, with $L$ t... | 0 | 0 | ['Math', 'Dynamic Programming', 'Python', 'Python3'] | 0 |
string-transformation | java + KMP | java-kmp-by-liuheng0213-mx1u | 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 | liuheng0213 | NORMAL | 2024-08-18T00:41:43.530836+00:00 | 2024-08-18T00:41:43.530871+00:00 | 32 | 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 |
string-transformation | Simple Math||100% tc and sc beat ||O(n) solution | simple-math100-tc-and-sc-beat-on-solutio-ltyh | 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 | Sdas_1905 | NORMAL | 2024-07-06T09:28:44.207301+00:00 | 2024-07-06T09:28:44.207334+00:00 | 83 | 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. $$O... | 0 | 1 | ['Math', 'C++'] | 0 |
string-transformation | String Transformation || Python 3 || Easy | string-transformation-python-3-easy-by-u-u5iq | Intuition\n Describe your first thoughts on how to solve this problem. \n\nThe problem requires transforming string s into string t through a series of cyclic o | user4609eh | NORMAL | 2024-05-23T14:05:00.463181+00:00 | 2024-05-23T14:05:00.463213+00:00 | 103 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe problem requires transforming string s into string t through a series of cyclic operations. The key intuition is to recognize the **cyclic nature of the transformation** and efficiently **count the number of valid transformations us... | 0 | 0 | ['Python3'] | 0 |
string-transformation | Simple Solution - Rolling Hash + Observation | simple-solution-rolling-hash-observation-iwum | While this problem can be solved in multiple ways, I wanted to share my solution which only uses rolling hashes, binary exponentiation + Fermat\'s Little Theore | sternentaucher | NORMAL | 2023-11-07T00:30:46.202694+00:00 | 2023-11-07T00:30:46.202727+00:00 | 71 | false | While this problem can be solved in multiple ways, I wanted to share my solution which only uses rolling hashes, binary exponentiation + Fermat\'s Little Theorem.\n\nFirst oberservation is that the relative order of elements does not change. Therefore, after an operation, we either end at the 0th, 1st, 2nd, ..., (n-1)t... | 0 | 0 | ['C++'] | 0 |
string-transformation | C++ solution | c-solution-by-pejmantheory-9r2t | 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 | pejmantheory | NORMAL | 2023-11-01T09:45:52.106538+00:00 | 2023-11-01T09:45:52.106555+00:00 | 78 | 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 |
string-transformation | Python || Dynamic Programming | python-dynamic-programming-by-abhinav_51-lwgr | Intuition\nThe code aims to compute the number of ways to rearrange the string s after k rotations such that it equals string t. The core intuition is to utiliz | Abhinav_5136 | NORMAL | 2023-10-30T13:53:32.330232+00:00 | 2023-10-30T13:54:41.572763+00:00 | 265 | false | # Intuition\nThe code aims to compute the number of ways to rearrange the string s after k rotations such that it equals string t. The core intuition is to utilize the properties of rotating strings and mathematical deductions to derive a dynamic programming transition, reducing the problem complexity.\n\n# Approach - ... | 0 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
string-transformation | [Python] Easy Solution for Difficult Problem | String Hashing + Maths | python-easy-solution-for-difficult-probl-ewed | Intuition\n Describe your first thoughts on how to solve this problem. \nReally good problem, one needs to know various advance concepts to solve this problem.\ | tr1ten | NORMAL | 2023-10-24T05:20:09.744017+00:00 | 2023-10-24T05:20:09.744036+00:00 | 125 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nReally good problem, one needs to know various advance concepts to solve this problem.\n\nRealizations:\n1. t is just some rotation of s\n2. Now question reduces to finding number of ways to do such rotation in exactly k steps\n3. There o... | 0 | 0 | ['Python3'] | 0 |
string-transformation | Just a runnable solution | just-a-runnable-solution-by-ssrlive-qxfc | \nimpl Solution {\n const M: i64 = 1_000_000_007;\n\n fn add(x: i64, y: i64) -> i64 {\n if (x + y) >= Solution::M {\n x + y - Solution:: | ssrlive | NORMAL | 2023-10-18T09:37:15.216996+00:00 | 2023-10-18T09:37:15.217014+00:00 | 18 | false | ```\nimpl Solution {\n const M: i64 = 1_000_000_007;\n\n fn add(x: i64, y: i64) -> i64 {\n if (x + y) >= Solution::M {\n x + y - Solution::M\n } else {\n x + y\n }\n }\n\n fn mul(x: i64, y: i64) -> i64 {\n x * y % Solution::M\n }\n\n fn getz(s: &str) -... | 0 | 0 | ['Rust'] | 0 |
string-transformation | Python, solving a problem without being a genius. Matrix exponentiation + z-function | python-solving-a-problem-without-being-a-bjwu | Intuition\n\nThis is one of the problems that I almost solved during the competition and was very disappointed to not fully solve it.\n\n-------------------\n\n | salvadordali | NORMAL | 2023-10-05T07:24:44.336775+00:00 | 2023-10-05T07:24:44.336799+00:00 | 97 | false | # Intuition\n\nThis is one of the problems that I almost solved during the competition and was very disappointed to not fully solve it.\n\n-------------------\n\nFirst it is clear that the result is zero if a `s2` can\'t be created from `s1` with one operation. Which you can easily check with `if s2 in s1 + s1`\n\nI wa... | 0 | 0 | ['Python3'] | 0 |
string-transformation | O(n+m+logk) kmp and fastmod | onmlogk-kmp-and-fastmod-by-lsfhv-b5wg | Use KMP (or any other algorithm) to find all occurances of t in s + s\n\nNotice that from taking any suffix and putting it at the front, is the same as just som | Lsfhv | NORMAL | 2023-09-14T19:12:06.341932+00:00 | 2023-09-14T19:12:06.341955+00:00 | 61 | false | Use KMP (or any other algorithm) to find all occurances of `t` in `s + s`\n\nNotice that from taking any suffix and putting it at the front, is the same as just some rotation in `s + s`. Let `i` be the index that corressponds to which rotation we are looking at. \nFor example in `abcd`, `s + s = abcdabcd` `i = 0` corr... | 0 | 1 | ['Python3'] | 0 |
string-transformation | Java easy solution --> String Transformation | java-easy-solution-string-transformation-yui9 | 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 | ZIDDIRAJ | NORMAL | 2023-09-14T02:29:54.071354+00:00 | 2023-09-14T02:29:54.071374+00:00 | 568 | 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 | ['Math', 'String', 'Dynamic Programming', 'Java'] | 0 |
string-transformation | [C++] Interesting linear recurrence with matrix exponentiation | c-interesting-linear-recurrence-with-mat-4iii | Intuition\nFirst notice that the operation reduces to rotations of at least 1 position. \n\nLet the target rotation be r, and we check how many such rotations t | nicholasfoocl | NORMAL | 2023-09-13T15:53:41.689871+00:00 | 2023-09-13T15:53:41.689901+00:00 | 89 | false | # Intuition\nFirst notice that the operation reduces to rotations of at least 1 position. \n\nLet the target rotation be `r`, and we check how many such rotations there are. Let the number of target rotations be `ct`.\n\nFrom there, we can work out a recurrence for dp:\n`v[i][0]` = number of ways to reach one of the ct... | 0 | 0 | ['C++'] | 0 |
string-transformation | KMP + Matrix exponentiation 90% faster | kmp-matrix-exponentiation-90-faster-by-v-rysu | Intuition\n Describe your first thoughts on how to solve this problem. \nthese transformations are nothing but rotations of S.\nsteps:\n1. check whether T is a | vedantnaudiyal | NORMAL | 2023-09-13T12:04:26.235075+00:00 | 2023-09-13T12:04:26.235098+00:00 | 93 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nthese transformations are nothing but rotations of S.\nsteps:\n1. check whether T is a possible rotation of S or not?\n2. if yes then no of possible rotations for a string str of length n will be n(including itself, rotating at i-> 0..n-1... | 0 | 0 | ['C++'] | 0 |
string-transformation | string hash and dp | string-hash-and-dp-by-sae_young-5cow | Complexity\n- Time complexity:\nO(max(N, log2K))\n\n- Space complexity:\nO(max(N, log2K))dynami\n\n# Code\n\nclass Solution {\n#define MOD 1000000007\n\npublic: | sae_young | NORMAL | 2023-09-12T23:30:38.068164+00:00 | 2023-09-12T23:30:38.068188+00:00 | 164 | false | # Complexity\n- Time complexity:\nO(max(N, log2K))\n\n- Space complexity:\nO(max(N, log2K))dynami\n\n# Code\n```\nclass Solution {\n#define MOD 1000000007\n\npublic:\n long long dp[55][2] = {{}};\n\n void init(long long k, int n) {\n dp[0][0] = 1;\n dp[0][1] = 0;\n\n int logK = (int)log2(k);\... | 0 | 0 | ['Dynamic Programming', 'String Matching', 'C++'] | 0 |
string-transformation | Binary Lifiting | binary-lifiting-by-xd91-i7nw | Intuition\nUsed binary lifting in several last contests\n\n# Approach\nBinary lifting\n\n# Complexity\n- Time complexity:\nhard to say it\'s O(n), the string co | xd91 | NORMAL | 2023-09-11T00:56:30.693493+00:00 | 2023-09-11T01:05:20.329917+00:00 | 40 | false | # Intuition\nUsed binary lifting in several last contests\n\n# Approach\nBinary lifting\n\n# Complexity\n- Time complexity:\nhard to say it\'s O(n), the string comparison is slow, and I failed to optimize it. String hashing gave me collisions. Hint shows that KMP should be used.\n\n- Space complexity: O(n)\n\n\n# Code\... | 0 | 0 | ['Python3'] | 0 |
string-transformation | Magic Solution | No DP No Tables | Pure Math | C++ | magic-solution-no-dp-no-tables-pure-math-8n4x | Intuition\nFirst of all let define that operations are actially do.\nImagine our string t as a looped string with some point, which we\'ll call the starting pos | KOCMOHABT | NORMAL | 2023-09-10T22:01:48.262357+00:00 | 2023-09-12T12:32:21.250776+00:00 | 105 | false | # Intuition\nFirst of all let define that operations are actially do.\nImagine our string $$t$$ as a looped string with some point, which we\'ll call the starting position. Any operation just rolls over our string and changes this position. Operation with a suffix length of $$l$$ clearly shifts our position by $$l$$.\n... | 0 | 0 | ['C++'] | 0 |
string-transformation | C++ Rabin-Karp + DP-Matrix Exponentiation. | c-rabin-karp-dp-matrix-exponentiation-by-gzis | Initial intuition is that our operation is a rotation operation only. Just rotation, not swap or anything suspicious like that. There are only upto N unique rot | satj | NORMAL | 2023-09-10T21:27:48.231011+00:00 | 2023-09-12T16:28:27.777842+00:00 | 54 | false | Initial intuition is that our operation is a rotation operation only. Just rotation, not swap or anything suspicious like that. There are only upto `N` unique rotations.\n\nUse $$previous\\ knowledge \u2122$$ to do Rabin-Karp/KMP/Z to find how many ways we can get from out initial string `s` to target string `t` by rot... | 0 | 0 | ['C'] | 0 |
string-transformation | [c++] rolling hash | c-rolling-hash-by-lyronly-0yc2 | 1 Use similar concept as Binary lifting for caculatting the transform matrix for k.\n2 use rolling hash to detech pattern in string s\'s rotations.\n\n\nclass S | lyronly | NORMAL | 2023-09-10T19:15:00.710478+00:00 | 2023-09-10T19:15:00.710501+00:00 | 25 | false | 1 Use similar concept as Binary lifting for caculatting the transform matrix for k.\n2 use rolling hash to detech pattern in string s\'s rotations.\n\n```\nclass Solution {\npublic:\n const int mod = (int)(1e9 +7);\n int add(int x, int y) {\n if ((x += y) >= mod) {\n x -= mod;\n }\n ... | 0 | 0 | [] | 0 |
string-transformation | JS Solution | js-solution-by-cutetn-mth3 | LOL contests these days are painfully hard.\n\n# Approach\n- To save your time, the full solution involves hash, inversed modulo, generating function.\n\n- let | CuteTN | NORMAL | 2023-09-10T16:40:24.255040+00:00 | 2023-09-10T16:40:24.255062+00:00 | 188 | false | LOL contests these days are painfully hard.\n\n# Approach\n- To save your time, the full solution involves **hash**, **inversed modulo**, **generating function**.\n\n- let `l = t.length`\n- A simple trick to find a rotation of `s` that equals to `t` is to find all occurrence of `t` in `s + s` (which starts before index... | 0 | 0 | ['Math', 'Dynamic Programming', 'JavaScript'] | 0 |
string-transformation | My Solution | my-solution-by-hope_ma-i2zd | \n/**\n * the dp solution is employed\n *\n * 1. dp1[i] stands for the number of the ways\n * in which `s` can be transformed into `t` in exactly `i` operati | hope_ma | NORMAL | 2023-09-10T10:47:51.806937+00:00 | 2023-12-10T11:34:17.333849+00:00 | 15 | false | ```\n/**\n * the dp solution is employed\n *\n * 1. dp1[i] stands for the number of the ways\n * in which `s` can be transformed into `t` in exactly `i` operations\n * 2. dp2[i] stands for the number of the ways\n * in which `s` can be tranfromed into a string which is not equal to `t`\n * in exactly `i` opera... | 0 | 0 | [] | 0 |
string-transformation | kmp, binary lifting and matrix multiply | kmp-binary-lifting-and-matrix-multiply-b-34bo | \n 1) use KMP to find all rotation index locations\n\n 2) Suppose that the initial state for number of ways is [x, y].\n x is the ways for zero, and y | wuzhenhai | NORMAL | 2023-09-10T08:45:21.326183+00:00 | 2023-09-10T08:46:58.849034+00:00 | 91 | false | \n 1) use KMP to find all rotation index locations\n\n 2) Suppose that the initial state for number of ways is [x, y].\n x is the ways for zero, and y is the ways for none-zeros.\n The next state after one operation can use the following formula:\n [new_x, new_y] = [x,y] * M, M = [[0,1], [n-1, n-2]].\n ... | 0 | 0 | ['C++'] | 0 |
string-transformation | Transition Matrix Solution | transition-matrix-solution-by-hongyili-2qy0 | Intuition\n Describe your first thoughts on how to solve this problem. \nFrist find number of rotation-shift\'s to make\n\nSecond, create transition matrix of r | hongyili | NORMAL | 2023-09-10T04:26:04.014473+00:00 | 2023-09-10T04:26:04.014491+00:00 | 190 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFrist find number of rotation-shift\'s to make\n\nSecond, create transition matrix of rotation-shift. This matrix is tricky, it has 0 in diagonal and 1 elsewhere. If we calculate powers of this matrix, we will see there are only 2 values,... | 0 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.