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
the-earliest-and-latest-rounds-where-players-compete
C++ solutions
c-solutions-by-infox_92-3ear
\n\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int st
Infox_92
NORMAL
2022-12-03T15:30:38.580602+00:00
2022-12-03T15:30:38.580635+00:00
118
false
```\n```\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int state){\n if(i1 < i2){\n if(i2 != f && i2 != s){\n perm(len, f, s, round, i1+1, i2-1, state | (1 << i1)); \n ...
0
0
['C++']
0
the-earliest-and-latest-rounds-where-players-compete
C++ solutions
c-solutions-by-infox_92-q748
\n\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int st
Infox_92
NORMAL
2022-12-03T15:30:22.314836+00:00
2022-12-03T15:30:22.314869+00:00
89
false
```\n```\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int state){\n if(i1 < i2){\n if(i2 != f && i2 != s){\n perm(len, f, s, round, i1+1, i2-1, state | (1 << i1)); \n ...
0
0
['C++']
0
the-earliest-and-latest-rounds-where-players-compete
[c++] dp solution
c-dp-solution-by-projectcoder-m6td
\nconst int N = 10 + 3e1;\n\nint f[N][N][N];\nint g[N][N][N];\n\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int T, int A,
projectcoder
NORMAL
2022-11-18T11:32:41.482323+00:00
2022-11-18T11:32:41.482361+00:00
57
false
```\nconst int N = 10 + 3e1;\n\nint f[N][N][N];\nint g[N][N][N];\n\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int T, int A, int B) { \n memset(f, 0x3f, sizeof(f));\n memset(g, 0xcf, sizeof(g));\n f[2][1][2] = 1;\n g[2][1][2] = 1;\n \n ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
python solution (faster 90%)
python-solution-faster-90-by-dugu0607-pjnz
\tclass Solution:\n\t\tdef earliestAndLatest(self, n, F, S):\n\t\t\tans = set()\n\t\t\tdef dfs(pos, i):\n\t\t\t\tM, pairs = len(pos), []\n\t\t\t\tif M < 2: retu
Dugu0607
NORMAL
2022-10-10T12:07:28.947906+00:00
2022-10-10T12:07:28.947962+00:00
55
false
\tclass Solution:\n\t\tdef earliestAndLatest(self, n, F, S):\n\t\t\tans = set()\n\t\t\tdef dfs(pos, i):\n\t\t\t\tM, pairs = len(pos), []\n\t\t\t\tif M < 2: return\n\n\t\t\t\tfor j in range(M//2):\n\t\t\t\t\ta, b = pos[j], pos[-1-j]\n\t\t\t\t\tif (a, b) == (F, S):\n\t\t\t\t\t\tans.add(i)\n\t\t\t\t\t\treturn\n\t\t\t\t\ti...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Java | Top-Down DP | Nested Recursion | Comments
java-top-down-dp-nested-recursion-commen-kqeo
This recursion has 2 layers. The top layer is for choosing whether the right or left player wins, the bottom layer is for advancing the round.\n\nI only memo th
Student2091
NORMAL
2022-07-13T21:58:32.475461+00:00
2022-07-13T22:00:08.486232+00:00
172
false
This recursion has 2 layers. The top layer is for choosing whether the right or left player wins, the bottom layer is for advancing the round.\n\nI only memo the round layer and it is good enough.\n\nIt reminds me of some DP medium questions which can also be solved this way. The num of ways to stack the brick one and ...
0
0
['Java']
0
the-earliest-and-latest-rounds-where-players-compete
C++ DP+permutation | Easy to read
c-dppermutation-easy-to-read-by-tangerri-i7cv
\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int stat
tangerrine2112
NORMAL
2022-07-06T08:06:35.377745+00:00
2022-07-06T08:06:35.377770+00:00
89
false
```\nclass Solution {\nprivate:\n int dp[28][28][28];\n int Min = INT_MAX, Max = 0;\n void perm(int len, int f, int s, int round, int i1, int i2, int state){\n if(i1 < i2){\n if(i2 != f && i2 != s){\n perm(len, f, s, round, i1+1, i2-1, state | (1 << i1)); \n }\n ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Python | Top Down DP | Easier to Understand
python-top-down-dp-easier-to-understand-2v7uo
```\n#based on https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/discuss/1268560/Python-simple-top-down-dp-solution-O(N4)\nclas
aryonbe
NORMAL
2022-06-15T00:06:19.299777+00:00
2022-06-15T00:06:19.299813+00:00
153
false
```\n#based on https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/discuss/1268560/Python-simple-top-down-dp-solution-O(N4)\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n @cache\n def dfs(l, r, m):\n ...
0
0
['Depth-First Search', 'Python']
0
the-earliest-and-latest-rounds-where-players-compete
中文 写得非常好 dp
zhong-wen-xie-de-fei-chang-hao-dp-by-wuz-1q0o
https://leetcode-cn.com/problems/the-earliest-and-latest-rounds-where-players-compete/solution/dong-tai-gui-hua-fen-lei-tao-lun-zhuan-y-9pjd/
wuzhenhai
NORMAL
2022-02-24T04:05:36.513433+00:00
2022-02-24T04:05:36.513470+00:00
153
false
https://leetcode-cn.com/problems/the-earliest-and-latest-rounds-where-players-compete/solution/dong-tai-gui-hua-fen-lei-tao-lun-zhuan-y-9pjd/
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
[Python] BFS + bit mask
python-bfs-bit-mask-by-watashij-s1bm
The idea is simple: encoding the player state using bit array, then generate competing pairs, and based on the pairs, we can generate the next state. \n\n## Exa
watashij
NORMAL
2021-11-02T21:42:49.866807+00:00
2021-12-22T16:26:06.046466+00:00
144
false
The idea is simple: encoding the player state using bit array, then generate competing pairs, and based on the pairs, we can generate the next state. \n\n## Example\nLet\'s say we have 5 players, then the initial bit array would be `[1, 1, 1, 1, 1]`. We can generate pairs using the rules stated in the question, so we h...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
C++ dfs
c-dfs-by-colinyoyo26-k0sr
200 ms\n\nclass Solution {\npublic:\n void dfs (int l, int r, int mask, int round) {\n if (l <= r) {\n dfs(1 << 27, mask & -mask, mask, rou
colinyoyo26
NORMAL
2021-07-21T02:59:21.139282+00:00
2021-07-21T04:45:44.746947+00:00
217
false
200 ms\n```\nclass Solution {\npublic:\n void dfs (int l, int r, int mask, int round) {\n if (l <= r) {\n dfs(1 << 27, mask & -mask, mask, round + 1);\n } else if (l & ~mask) {\n dfs(l >> 1, r, mask, round);\n } else if (l & s && r & f) {\n maxans = max(maxans, r...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
1900. Python solution with details explanation, beats 40% solution
1900-python-solution-with-details-explan-fqok
class Solution:\n \'\'\'\n \n\t Definition of dp - It will return min and max rounds to compete first and second player\n 1. Will we give remaining p
shiavm-singh
NORMAL
2021-06-27T18:14:28.397878+00:00
2021-06-27T18:14:28.397940+00:00
271
false
class Solution:\n \'\'\'\n \n\t Definition of dp - It will return min and max rounds to compete first and second player\n 1. Will we give remaining players to dp, \n \n 2. In dp, we will go through n/2(integer) players and collect all pairs of player who is going to be against each other, \n ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
clean java memory dfs
clean-java-memory-dfs-by-chenyuanqin826-cjpu
\nclass Solution {\n int[][][][] mem = new int[29][29][29][2];\n public int[] earliestAndLatest(int n, int f, int s) {\n return helper(n, f - 1, s
chenyuanqin826
NORMAL
2021-06-26T14:43:05.270910+00:00
2021-06-26T14:43:05.270936+00:00
178
false
```\nclass Solution {\n int[][][][] mem = new int[29][29][29][2];\n public int[] earliestAndLatest(int n, int f, int s) {\n return helper(n, f - 1, s - 1);\n }\n \n public int[] helper(int n, int f, int s) {\n if (f == n - 1 - s){\n return new int[]{1, 1};\n }\n if ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Confusion with the testcase's expected output
confusion-with-the-testcases-expected-ou-3kmf
For testcase:\nInput: n = 5, firstPlayer = 1, secondPlayer =4\nExpected output is [2,2]\n\nround1:1,2,3,4,5\nround2: 1,4,3\nround3: 1,4\n\nWhat am I getting wro
ollob
NORMAL
2021-06-24T10:11:25.947347+00:00
2021-06-24T10:13:53.849370+00:00
108
false
For testcase:\nInput: n = 5, firstPlayer = 1, secondPlayer =4\nExpected output is [2,2]\n\nround1:**1**,2,3,**4**,5\nround2: **1**,**4**,3\nround3: **1**,**4**\n\nWhat am I getting wrong here? Thank you! (I hope I\'m not disturbing the community with my ignorance)
0
0
[]
1
the-earliest-and-latest-rounds-where-players-compete
[Python] - O(N^4) - Generate and Test + Explanation
python-on4-generate-and-test-explanation-wlqy
The basic stratgy is as follows: Given the postions of the two players in round N and round N+1, can you determine if it possible to transition from the old to
a-f-v
NORMAL
2021-06-21T10:04:51.092456+00:00
2021-06-22T18:51:11.955266+00:00
222
false
The basic stratgy is as follows: **Given the postions of the two players in round N and round N+1, can you determine if it possible to transition from the old to new configuration?** *A configuration is represented with only the positions of the two top players.*\n\nImagine this test takes time f(n). Then, we can gener...
0
0
['Python']
0
the-earliest-and-latest-rounds-where-players-compete
[Python] Backtracking with memoization
python-backtracking-with-memoization-by-8ya7b
\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n \n dp = {}\n\n def getComb(
rajat499
NORMAL
2021-06-17T04:42:42.341518+00:00
2021-06-17T04:42:42.341560+00:00
186
false
```\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n \n dp = {}\n\n def getComb(res, i, n):\n if i==n:\n return []\n curr = res[i]\n others = getComb(res, i+1, n)\n total = []\n ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
[C++]dfs and memorize dp
cdfs-and-memorize-dp-by-fangee-fkq9
2<=n<=28,so we can use int as the status of players ,\nuse dp to memorize answers of each status for avoiding duplicated calculation\n\nunordered_set<int> super
fangee
NORMAL
2021-06-16T03:52:25.628054+00:00
2021-06-16T03:52:25.628103+00:00
203
false
2<=n<=28,so we can use int as the status of players ,\nuse dp to memorize answers of each status for avoiding duplicated calculation\n```\nunordered_set<int> super;\nunordered_map<int, unordered_set<int>> mp;\nint mn = INT_MAX, mx = INT_MIN, nn;\n\nvoid dfs(int s, int level) {\n// cout << "hex:" << "i = " << hex << ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
[Python] Top-Down Dynamic Programming with Memorization
python-top-down-dynamic-programming-with-indq
\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n from functools import lru_cache\n
xuyfthu
NORMAL
2021-06-16T03:39:57.182663+00:00
2021-06-16T03:41:50.097084+00:00
87
false
```\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n from functools import lru_cache\n earliest, latest = float(\'inf\'), -1\n \n cur = n\n d = {n: 1}\n round = 2\n while cur > 2:\n cur = (cur + 1) ...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
(C++) 1900. The Earliest and Latest Rounds Where Players Compete
c-1900-the-earliest-and-latest-rounds-wh-x208
\n\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n firstPlayer -= 1, secondPlayer -= 1; \n
qeetcode
NORMAL
2021-06-15T15:36:25.435437+00:00
2021-06-15T15:36:25.435484+00:00
218
false
\n```\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n firstPlayer -= 1, secondPlayer -= 1; \n \n map<int, vector<int>> memo; \n function<vector<int>(int, int, int, int)> fn = [&](int r, int mask, int i, int j) {\n if (mem...
0
0
['C']
0
the-earliest-and-latest-rounds-where-players-compete
C++ | BitMasking
c-bitmasking-by-tanishbothra22-zcaj
\nclass Solution {\npublic:\nint a1=INT_MAX;\nint a2=INT_MIN;\n\nvoid dfs(int i,int j,int mask,int n,int first,int second,int t){\n \n if(i>=j){\n
tanishbothra22
NORMAL
2021-06-15T13:39:26.645057+00:00
2021-06-15T16:27:50.253790+00:00
195
false
```\nclass Solution {\npublic:\nint a1=INT_MAX;\nint a2=INT_MIN;\n\nvoid dfs(int i,int j,int mask,int n,int first,int second,int t){\n \n if(i>=j){\n return dfs(1,n,mask,n,first,second,t+1);\n }\n \n while(!(mask&(1<<i))&&i<j)i++;\n while(!(mask&(1<<j)) &&i<j)j--;\n if(i==j){\n ...
0
0
['C']
0
the-earliest-and-latest-rounds-where-players-compete
[c++] 16ms DP
c-16ms-dp-by-summerzhou-a8sg
This is a pretty good problem, I see the mask & simulation solution, DP solution, And greedy!\nVery satisfiled!\n\n\n\nstruct Value {\n int mn = INT_MAX;\n
summerzhou
NORMAL
2021-06-15T03:37:27.228804+00:00
2021-06-15T03:37:27.228853+00:00
102
false
This is a pretty good problem, I see the mask & simulation solution, DP solution, And greedy!\nVery satisfiled!\n\n```\n\nstruct Value {\n int mn = INT_MAX;\n int mx = INT_MIN;\n Value(int a, int b)\n {\n mn = a;\n mx = b;\n }\n Value()\n {}\n \n void update(Value& v)\n {\n...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Simple C++ code
simple-c-code-by-luoyuf-u1m8
\n\n void earliestAndLatest_(int a, int b, int& first, int& second, int n, vector<vector<vector<bool>>>& m, int curr) {\n \n if (a + b == n + 1
luoyuf
NORMAL
2021-06-14T00:18:03.601863+00:00
2021-06-14T00:18:03.601907+00:00
115
false
```\n\n void earliestAndLatest_(int a, int b, int& first, int& second, int n, vector<vector<vector<bool>>>& m, int curr) {\n \n if (a + b == n + 1) {\n first = min(curr, first);\n second = max(curr, second);\n return;\n }\n \n if (m[a][b][curr]) ret...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
JavaScript DFS
javascript-dfs-by-ektegjetost-6zgy
Relatively straightforward DFS. You can get away with a complete brute force if you want, though memoization will improve the runtime.\n\nYou probably also don\
ektegjetost
NORMAL
2021-06-13T22:32:06.828459+00:00
2021-06-13T22:32:06.828491+00:00
104
false
Relatively straightforward DFS. You can get away with a complete brute force if you want, though memoization will improve the runtime.\n\nYou probably also don\'t need a bitmask, but since ```n < 32```, may as well.\n\nWe\'ll use DFS, moving from player to player until we\'ve gone halfway through the list, since that m...
0
0
['Bit Manipulation', 'Depth-First Search', 'JavaScript']
0
the-earliest-and-latest-rounds-where-players-compete
bit mask + simulation + memorization
bit-mask-simulation-memorization-by-plus-6o3o
Unfortunately, I didn\'t solve this problem in the contest. I was struggling to solve a bug. \n\nAt first sight, this problem can be solved by search algorithm,
plus_minus
NORMAL
2021-06-13T21:11:59.378828+00:00
2021-06-13T21:11:59.378856+00:00
71
false
Unfortunately, I didn\'t solve this problem in the contest. I was struggling to solve a bug. \n\nAt first sight, this problem can be solved by search algorithm, either by dfs or backtracking. The input size is <= 28. At each step, half of the player will be eliminated. So the height of the recursion tree will be O(log(...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Why I am not getting TLE? passed in 208ms/6.2MB
why-i-am-not-getting-tle-passed-in-208ms-kk0i
Below is my Code which I think should get TLE.\n\n\nint mn,mx;\nint f,s,n;\nclass Solution {\npublic: \n void dfs(int deadmask,int i,int j,int round){\n
vineetjai
NORMAL
2021-06-13T13:29:50.416931+00:00
2021-06-13T13:31:43.568109+00:00
104
false
Below is my Code which I think should get TLE.\n\n```\nint mn,mx;\nint f,s,n;\nclass Solution {\npublic: \n void dfs(int deadmask,int i,int j,int round){\n \n while(i<n && deadmask &(1<<i)) i++;\n while(j>=0 && deadmask &(1<<j)) j--;\n // next round\n if(i>=j) dfs(deadmask,1,n,roun...
0
0
[]
1
the-earliest-and-latest-rounds-where-players-compete
Faster than 50% time, 100% Space in C++ and same solution gives a TLE in Python ;)
faster-than-50-time-100-space-in-c-and-s-v28d
\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int first, int second) {\n int minRound = INT_MAX, maxRound = INT_MIN;\n\n f
yozaam
NORMAL
2021-06-13T10:42:25.038567+00:00
2021-06-13T10:44:48.701455+00:00
175
false
```\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int first, int second) {\n int minRound = INT_MAX, maxRound = INT_MIN;\n\n function<void(int,int,int,int)> dfs = \n [&](int deadMask,int i,int j, int curRound) {\n \n while (i < j and deadMask & (1<<i...
0
0
['Depth-First Search', 'Recursion', 'C', 'Bitmask', 'Python']
0
the-earliest-and-latest-rounds-where-players-compete
[Python] keep string instead of bitmask
python-keep-string-instead-of-bitmask-by-rzyp
\n\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n step, first, last, xs = 0, 0, 0, [firstPlayer, secondPla
khoso
NORMAL
2021-06-13T10:28:14.955028+00:00
2021-06-13T10:52:36.789339+00:00
70
false
\n```\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n step, first, last, xs = 0, 0, 0, [firstPlayer, secondPlayer]\n # mark firstPlayer and secondPlayer as \'!\', others as \'.\'\n work = {\'!\'.join([ \'.\' * (y - x - 1) for x,y in zip([0] + xs, xs + [...
0
0
['Python']
0
the-earliest-and-latest-rounds-where-players-compete
[Python ] DP + Bitmask + Memoization
python-dp-bitmask-memoization-by-rsrs3-2jcx
\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n self.first = min(firstPlayer-1, secondPla
rsrs3
NORMAL
2021-06-13T07:36:44.197333+00:00
2021-06-13T07:36:44.197369+00:00
68
false
```\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n self.first = min(firstPlayer-1, secondPlayer-1)\n self.second = max(firstPlayer-1, secondPlayer-1)\n self.n=n-1\n self.dp = {}\n return self.rounds_helper((1<<n)-1, 0, se...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
C++ Solution using(push_back)->TLE and not using(push_back)376ms
c-solution-usingpush_back-tle-and-not-us-hyyo
Way1 -> not use push_back\n\nclass Solution {\npublic:\n unordered_set<long long>memo;\n int firstPlayer,secondPlayer,mn,mx;\n void helper(vector<int>&
Verdict_AC
NORMAL
2021-06-13T06:43:56.474731+00:00
2021-06-13T06:43:56.474777+00:00
70
false
Way1 -> not use push_back\n```\nclass Solution {\npublic:\n unordered_set<long long>memo;\n int firstPlayer,secondPlayer,mn,mx;\n void helper(vector<int>& arr,int round)\n {\n int n=arr.size();\n long long mod=1e9+7;\n long long now=0;\n for(auto &x:arr)\n {\n n...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
[C++] Recursion optimized 24 ms 32 MB
c-recursion-optimized-24-ms-32-mb-by-ash-ecrg
\n#pragma GCC optimize("Ofast")\n#pragma GCC optimize("unroll-loops")\n#pragma GCC optimize("inline")\n\nclass Solution {\npublic:\n int f,s,cur_level,mi,ma;
ashish23ks
NORMAL
2021-06-13T05:48:22.269261+00:00
2021-06-13T05:48:22.269292+00:00
69
false
```\n#pragma GCC optimize("Ofast")\n#pragma GCC optimize("unroll-loops")\n#pragma GCC optimize("inline")\n\nclass Solution {\npublic:\n int f,s,cur_level,mi,ma;\n vector<vector<int>> cur;\n vector<int> prev;\n //recurse all games\n void games(vector<int> & ans, int pos){\n if(prev.size()%2==0){\n ...
0
1
[]
0
the-earliest-and-latest-rounds-where-players-compete
C++ brute force
c-brute-force-by-cpcs-3nne
\nclass Solution {\n int earliest(int n, int x, int y, vector<vector<vector<int>>> &dp) {\n int& r = dp[n][x][y];\n if (r >= 0) {\n
cpcs
NORMAL
2021-06-13T05:17:48.104163+00:00
2021-06-13T05:17:48.104205+00:00
93
false
```\nclass Solution {\n int earliest(int n, int x, int y, vector<vector<vector<int>>> &dp) {\n int& r = dp[n][x][y];\n if (r >= 0) {\n return r;\n }\n if (x + y == n - 1) {\n return r = 1;\n }\n int round = n >> 1;\n if (n & 1) {\n con...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
Using Mask and Bitwise operations.
using-mask-and-bitwise-operations-by-van-w38k
```\n fun earliestAndLatest(n: Int, firstPlayer: Int, secondPlayer: Int): IntArray {\n return helper(1.shl(n + 1) - 1, 1, n, firstPlayer, secondPlayer
vanajag
NORMAL
2021-06-13T05:15:04.327333+00:00
2021-06-13T05:15:04.327362+00:00
65
false
```\n fun earliestAndLatest(n: Int, firstPlayer: Int, secondPlayer: Int): IntArray {\n return helper(1.shl(n + 1) - 1, 1, n, firstPlayer, secondPlayer, 1, n)\n }\n \n val db = HashMap<String, IntArray>()\n \n fun helper(mask: Int, s: Int, e: Int, f: Int, fs: Int, round: Int, n :Int): IntArray {...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
[Python] generate production and then DP
python-generate-production-and-then-dp-b-cd4c
\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n import functools\n \n def w
codefever
NORMAL
2021-06-13T04:36:20.932522+00:00
2021-06-13T04:36:20.932548+00:00
127
false
```\nclass Solution:\n def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:\n import functools\n \n def win(i, j, first, second):\n if i == j:\n return [i]\n if i in (first, second):\n return [i]\n i...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
C++ Easy Solution
c-easy-solution-by-sandhuamar1607-7zpm
\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n vector<int> result;\n int early= 1, l
sandhuamar1607
NORMAL
2021-06-13T04:26:49.956785+00:00
2021-06-13T04:26:49.956813+00:00
99
false
```\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n vector<int> result;\n int early= 1, latest= 1;\n vector<int> players;\n for(int i=1; i<=n; i++) players.push_back(i);\n int i=0, j=players.size()-1;\n while(1){\n ...
0
3
[]
1
the-earliest-and-latest-rounds-where-players-compete
Randomised Solution.
randomised-solution-by-saksham_2000-rsf0
define ll long long\n#define pb push_back\n#define vl vector\n#define all(x) x.begin(),x.end()\n\nclass Solution {\npublic:\n vector earliestAndLatest(int n,
saksham_2000
NORMAL
2021-06-13T04:17:27.246663+00:00
2021-06-13T04:17:27.246694+00:00
111
false
#define ll long long\n#define pb push_back\n#define vl vector<ll>\n#define all(x) x.begin(),x.end()\n\nclass Solution {\npublic:\n vector<int> earliestAndLatest(int n, int s1, int s2) {\n ll mn = 1e9, mx = 0;\n\n ll t = 1000;\n\n while (t--) {\n\n\n vl v;\n for (ll i = 1; i <= n; i++)v.pb(i);\n\n ...
0
0
['C']
0
the-earliest-and-latest-rounds-where-players-compete
[C++] DFS + Memorization
c-dfs-memorization-by-hujc-r4kj
The min and max round for the two player to meet is determined by the state [n, firstPlayer, secondPlay], where the three number are the number of players, firs
hujc
NORMAL
2021-06-13T04:06:10.538272+00:00
2021-06-13T07:47:47.854060+00:00
165
false
The min and max round for the two player to meet is determined by the state `[n, firstPlayer, secondPlay]`, where the three number are the number of players, first player position and second player position. And for going into next round, we do not need to track the actual player position at the beginning but just thei...
0
0
[]
1
the-earliest-and-latest-rounds-where-players-compete
bit mask+2DFS optimized with memorization. 0ms/2.2MB
bit-mask2dfs-optimized-with-memorization-8fsk
State = [fp is the ith surviver][sp is the jth surviver][the total number of the rest survivers]\nWritten in Golan.\n\nfunc earliestAndLatest(n int, fp int, sp
bcb98801xx
NORMAL
2021-06-13T04:04:03.298631+00:00
2021-06-14T03:45:35.295065+00:00
138
false
State = ```[fp is the ith surviver][sp is the jth surviver][the total number of the rest survivers]```\nWritten in Golan.\n```\nfunc earliestAndLatest(n int, fp int, sp int) []int {\n fp--\n sp--\n \n if fp > sp {\n fp, sp = sp, fp\n }\n \n ans := []int{100, 0}\n vis := [28][28][27]bool{}...
0
0
[]
0
the-earliest-and-latest-rounds-where-players-compete
C++ BITMASKS | RECURSIVE
c-bitmasks-recursive-by-saber2k18-j5tx
-> Consider all possiblites on both sides of the current array.\n-> Notice we only need half the array size for full information\n-> So complexity would be O(2^
saber2k18
NORMAL
2021-06-13T04:02:36.049080+00:00
2021-06-13T04:04:34.604981+00:00
155
false
-> Consider all possiblites on both sides of the current array.\n-> Notice we only need half the array size for full information\n-> So complexity would be O(2^(n/2)*n)\n\n\n```\nclass Solution {\npublic:\n int lm,hm;\n void solve(set<int> &now,int round,int fp,int sp){\n \n if(!now.count(fp) or !now...
0
0
[]
1
find-the-shortest-superstring
Travelling Salesman Problem
travelling-salesman-problem-by-wangzi614-byrh
Travelling Salesman Problem\n\n1. graph[i][j] means the length of string to append when A[i] followed by A[j]. eg. A[i] = abcd, A[j] = bcde, then graph[i][j] =
wangzi6147
NORMAL
2018-11-18T04:17:52.261718+00:00
2018-11-18T04:17:52.261758+00:00
73,827
false
[Travelling Salesman Problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem)\n\n1. `graph[i][j]` means the length of string to append when `A[i]` followed by `A[j]`. eg. `A[i] = abcd`, `A[j] = bcde`, then `graph[i][j] = 1`\n2. Then the problem becomes to: find the shortest path in this graph which visits ev...
324
8
[]
36
find-the-shortest-superstring
[Python] dp on subsets solution - 3 solutions + oneliner, explained
python-dp-on-subsets-solution-3-solution-6pvg
This is actually Travelling salesman problem (TSP) problem: if we look at our strings as nodes, then we can evaluate distance between one string and another, fo
dbabichev
NORMAL
2021-05-23T10:28:00.219962+00:00
2021-05-24T12:21:25.674867+00:00
7,094
false
This is actually Travelling salesman problem (TSP) problem: if we look at our strings as nodes, then we can evaluate distance between one string and another, for example for `abcde` and `cdefghij` distance is 5, because we need to use 5 more symbols `fghij` to continue first string to get the second. Note, that this is...
106
19
['Dynamic Programming', 'Bitmask']
7
find-the-shortest-superstring
python bfs solution with detailed explanation(with extra Chinese explanation)
python-bfs-solution-with-detailed-explan-weq6
you can get Chinese explanation here\n\nFirst, we convert this problem into a graph problem.\nfor instance, A = ["catg","ctaagt","gcta","ttca","atgcatc"]\nwe re
bupt_wc
NORMAL
2018-11-19T05:50:57.136758+00:00
2018-11-19T05:50:57.136824+00:00
5,695
false
you can get Chinese explanation [here](https://buptwc.github.io/2018/11/19/Leetcode-943-Find-the-Shortest-Superstring/)\n\nFirst, we convert this problem into a graph problem.\nfor instance, `A = ["catg","ctaagt","gcta","ttca","atgcatc"]`\nwe regard each string in A as a node, and regard the repeat_length of two string...
66
3
[]
12
find-the-shortest-superstring
Shortest Hamiltonian Path in weighted digraph (with instructional explanation)
shortest-hamiltonian-path-in-weighted-di-xmce
1. Formulate the problem as a graph problem\nLet\'s consider each string as a node on the graph, using their overlapping range as a similarity measure, then the
lambdas
NORMAL
2018-11-28T03:17:36.758036+00:00
2018-11-28T03:17:36.758078+00:00
16,644
false
***1. Formulate the problem as a graph problem***\nLet\'s consider each string as a node on the graph, using their overlapping range as a similarity measure, then the edge from string A to string B is defined as:\n```\n(A,B) = len(A) - overlapping(tail of A to head of B), \neg A="catg" B= "atgcatc", overlapping is "...
54
2
[]
11
find-the-shortest-superstring
Clean python DP with explanations
clean-python-dp-with-explanations-by-ygt-8fyo
python\nclass Solution:\n def shortestSuperstring(self, A):\n """\n :type A: List[str]\n :rtype: str\n """\n # construct a
ygt2016
NORMAL
2018-11-18T08:46:59.930697+00:00
2018-11-18T08:46:59.930736+00:00
5,191
false
```python\nclass Solution:\n def shortestSuperstring(self, A):\n """\n :type A: List[str]\n :rtype: str\n """\n # construct a directed graph\n # node i => A[i]\n # weights are represented as an adjacency matrix:\n # shared[i][j] => length saved by concate...
37
1
[]
6
find-the-shortest-superstring
C++ solution in less than 30 lines
c-solution-in-less-than-30-lines-by-reim-na8y
This solution is less than 30 lines if comments are excluded.\nInstead of an int dp matrix, I use string dp matrix directly. Therefore the reconstruction is a l
reimu
NORMAL
2018-11-18T21:28:23.099007+00:00
2018-11-18T21:28:23.099072+00:00
5,827
false
This solution is less than 30 lines if comments are excluded.\nInstead of an int dp matrix, I use string dp matrix directly. Therefore the reconstruction is a little bit easier at the expense of more memory use (but same complexity if only n is counted). The string dp matrix idea is from the jave solution of @uwi. \n\n...
31
3
[]
3
find-the-shortest-superstring
LeetCode Weekly Contest 111 screencast (rank 12)
leetcode-weekly-contest-111-screencast-r-g72c
https://www.youtube.com/watch?v=4VzpJzaY2l4
cuiaoxiang
NORMAL
2018-11-18T04:26:09.109072+00:00
2018-11-18T04:26:09.109114+00:00
4,608
false
https://www.youtube.com/watch?v=4VzpJzaY2l4
27
7
[]
13
find-the-shortest-superstring
[C++] TSP - Hamiltonian Path (Not tour) - Simple code
c-tsp-hamiltonian-path-not-tour-simple-c-oz1r
\n#define INF 0x3f3f3f3f\n\nclass Solution {\n int VISITED_ALL, n;\n vector < vector < int > > dist, path, dp;\npublic:\n int calcDist(string a, string
vismit2000
NORMAL
2021-01-17T08:04:37.957840+00:00
2021-01-17T08:06:33.461521+00:00
3,448
false
```\n#define INF 0x3f3f3f3f\n\nclass Solution {\n int VISITED_ALL, n;\n vector < vector < int > > dist, path, dp;\npublic:\n int calcDist(string a, string b){\n for(int i = 0; i < a.length(); i++)\n if(b.rfind(a.substr(i), 0) == 0)\n return b.length() - (a.length() - i);\n ...
21
0
['Dynamic Programming', 'C', 'Bitmask', 'C++']
4
find-the-shortest-superstring
Python Recursion with Memory
python-recursion-with-memory-by-infinute-xips
Many thanks to @ygt2016. The original code is here. I converted the code to recursion, which might be a little easier to understand. Hope this is helpful. \nThe
infinute
NORMAL
2019-03-10T22:52:37.798229+00:00
2019-03-10T22:52:37.798291+00:00
2,051
false
Many thanks to @ygt2016. The original code is [here](https://leetcode.com/problems/find-the-shortest-superstring/discuss/195077/Clean-python-DP-with-explanations). I converted the code to recursion, which might be a little easier to understand. Hope this is helpful. \nThe general idea is:\n1. Build a (dense) graph whos...
17
0
[]
3
find-the-shortest-superstring
[C++] Easy to understand-Simple code
c-easy-to-understand-simple-code-by-i_an-th4c
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
i_anurag_mishra
NORMAL
2023-07-30T15:24:12.696066+00:00
2023-07-30T15:24:12.696090+00:00
1,687
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)$$ --...
16
0
['Dynamic Programming', 'Memoization', 'Bitmask', 'C++']
4
find-the-shortest-superstring
Rewrite the official solution in C++
rewrite-the-official-solution-in-c-by-vi-y7wd
Just rewrite the official solution in C++\n\n\nstring shortestSuperstring(vector<string>& A) {\n int n = A.size();\n \n vector<vector<int>>
victor_fw
NORMAL
2018-11-28T07:53:56.943343+00:00
2018-11-28T07:53:56.943384+00:00
2,684
false
Just rewrite the official solution in C++\n\n```\nstring shortestSuperstring(vector<string>& A) {\n int n = A.size();\n \n vector<vector<int>> overlaps(n, vector<int>(n));\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n int m = min(A[i].size(), A[j...
16
1
[]
1
find-the-shortest-superstring
JS, Python | Detailed Traveling Salesperson Problem Solution w/ Explanation
js-python-detailed-traveling-salesperson-ygky
(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n
sgallivan
NORMAL
2021-05-26T11:41:10.526758+00:00
2021-05-26T11:42:43.561443+00:00
1,960
false
*(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\n**Overview:**\n - _Build a map of **suffixes**._\n - _Use **suffixes** to help build the **edges** matrix of character overlaps in only **...
14
0
['Python', 'JavaScript']
0
find-the-shortest-superstring
A* search, python implementation 64ms pass
a-search-python-implementation-64ms-pass-xub9
As the problem is almost as difficult as the traveling salesman problem, I think a good pruning method is necessary.\nTherefore, I tried the A search algorithms
hwp
NORMAL
2019-01-18T16:15:03.959208+00:00
2019-01-18T16:15:03.959278+00:00
1,383
false
As the problem is almost as difficult as the traveling salesman problem, I think a good pruning method is necessary.\nTherefore, I tried the A* search algorithms.\n\nHere is the idea:\n\n1. Imagine a graph. Each node is a sequence of a subset of words.\n2. Node *x* is connected to node *y* by appending one word *i* to ...
9
0
[]
2
find-the-shortest-superstring
💥 TypeScript | Runtime beats 100.00%, Memory beats 75.00% [EXPLAINED]
typescript-runtime-beats-10000-memory-be-apjw
Intuition\nI need to form the shortest string containing all given words by overlapping them as much as possible. It\'s like fitting words together with maximum
r9n
NORMAL
2024-09-10T21:22:44.840935+00:00
2024-09-10T21:22:44.840961+00:00
118
false
# Intuition\nI need to form the shortest string containing all given words by overlapping them as much as possible. It\'s like fitting words together with maximum overlap to minimize the total length.\n\n\n# Approach\nEach bit in the mask tracks which words are included. I calculate the overlap between every word pair ...
8
0
['TypeScript']
0
find-the-shortest-superstring
Java | DP | Bitmask
java-dp-bitmask-by-monsterspyy-p34y
\nclass Solution {\n \n String[][] lookup;\n \n String superString(String[] A, int last, int bitmask, String[][] dp){\n String res = ""; \n
monsterspyy
NORMAL
2020-06-30T14:20:57.374155+00:00
2020-06-30T14:20:57.374207+00:00
1,173
false
```\nclass Solution {\n \n String[][] lookup;\n \n String superString(String[] A, int last, int bitmask, String[][] dp){\n String res = ""; \n int minLength = Integer.MAX_VALUE/2;\n if(dp[last][bitmask] != null)\n return dp[last][bitmask];\n \n for(int i=0;i<A...
8
1
['Dynamic Programming', 'Bitmask', 'Java']
1
find-the-shortest-superstring
Greedy Solution is Wrong . Proof
greedy-solution-is-wrong-proof-by-jaidee-8cse
Below is my solution based on a Greedy approach which got AC but when i looked into the solution where DP, BFS or TSP is used i felt that greedy might not be th
jaideep_dahiya
NORMAL
2021-05-27T05:13:46.571800+00:00
2021-05-27T05:13:46.571840+00:00
660
false
Below is my solution based on a **Greedy** approach which got **AC** but when i looked into the solution where DP, BFS or TSP is used i felt that greedy might not be the correct solution.\n\nSo after some searching found this guys comment **@Cronek** showing this testcase\n```"abcd", "bcde", "cdbc"``` . According to th...
7
0
[]
0
find-the-shortest-superstring
C++ | DP + Graph + BitMask with comments for understanding
c-dp-graph-bitmask-with-comments-for-und-43rk
\n\tclass Solution {\n\tpublic: \n\n\t\t// cost to append word2 to word1\n\t\t// cost represents extra characters we should add after word1 so that word2 bec
rbs_
NORMAL
2022-08-16T12:07:37.512371+00:00
2022-08-16T12:08:31.748168+00:00
1,805
false
\n\tclass Solution {\n\tpublic: \n\n\t\t// cost to append word2 to word1\n\t\t// cost represents extra characters we should add after word1 so that word2 becomes suffix\n\t\tint getCost(string &word1, string &word2){\n\t\t\tint n1 = word1.size();\n\t\t\tint n2 = word2.size();\n\n\t\t\tfor(int i=0; i<n1; i++){\n\t\t\...
6
0
[]
0
find-the-shortest-superstring
[C++] DP
c-dp-by-codedayday-mt5i
Approach 1: DP [1]\n\nclass Solution {\npublic: \n string shortestSuperstring(vector<string>& A) {\n const int n = A.size();\n vector<vector<in
codedayday
NORMAL
2021-05-23T15:57:38.530376+00:00
2021-05-23T16:01:06.321789+00:00
2,310
false
Approach 1: DP [1]\n```\nclass Solution {\npublic: \n string shortestSuperstring(vector<string>& A) {\n const int n = A.size();\n vector<vector<int> > g(n, vector<int>(n));\n for(int i = 0; i < n; i++)\n for(int j = 0; j < n; j++){\n g[i][j] = A[j].length();\n ...
6
0
['Dynamic Programming', 'C']
0
find-the-shortest-superstring
Single Handedly C++ Paste Accepted
single-handedly-c-paste-accepted-by-khac-ag54
\nclass Solution {\npublic:\n vector<int>len;\n vector<vector<int>>overlap;\n vector<vector<int>>dp;\n int n;\n map<pair<int, int>, int>mp;\n
khacker
NORMAL
2021-05-23T07:55:14.822476+00:00
2021-05-23T07:55:14.822507+00:00
432
false
```\nclass Solution {\npublic:\n vector<int>len;\n vector<vector<int>>overlap;\n vector<vector<int>>dp;\n int n;\n map<pair<int, int>, int>mp;\n int solve(int idx, int mask){\n if(mask == (1 << n) - 1) return 0;\n if(dp[idx][mask] != -1)return dp[idx][mask];\n dp[idx][mask] = INT_...
6
6
[]
0
find-the-shortest-superstring
C++ SOLUTION
c-solution-by-saurabhvikastekam-gdqs
\nclass Solution {\npublic:\n vector<int>len;\n vector<vector<int>>overlap;\n vector<vector<int>>dp;\n int n;\n map<pair<int, int>, int>mp;\n
SaurabhVikasTekam
NORMAL
2021-05-23T07:45:50.238324+00:00
2021-05-23T07:49:19.776893+00:00
2,205
false
```\nclass Solution {\npublic:\n vector<int>len;\n vector<vector<int>>overlap;\n vector<vector<int>>dp;\n int n;\n map<pair<int, int>, int>mp;\n int solve(int idx, int mask){\n if(mask == (1 << n) - 1) return 0;\n if(dp[idx][mask] != -1)return dp[idx][mask];\n dp[idx][mask] = INT_...
6
1
['C', 'C++']
0
find-the-shortest-superstring
Python test cases does not check type (100% time and space "Funny" )
python-test-cases-does-not-check-type-10-frch
\nclass Solution(object):\n def shortestSuperstring(self, A):\n return A\n
gsbhardwaj27
NORMAL
2021-02-06T09:39:24.006753+00:00
2021-02-06T09:39:24.006781+00:00
271
false
```\nclass Solution(object):\n def shortestSuperstring(self, A):\n return A\n```
6
4
[]
2
find-the-shortest-superstring
Python AC concise solution ~132 ms
python-ac-concise-solution-132-ms-by-cen-14m9
First, we analyze connections between any two string(a, b) in A:\n\t We get l, longest length of b that a ends with. \n\t In merged[a] array, we will have b str
cenkay
NORMAL
2018-11-18T17:35:43.944761+00:00
2018-11-18T17:35:43.944801+00:00
897
false
* First, we analyze connections between any two string(a, b) in A:\n\t* We get l, longest length of b that a ends with. \n\t* In merged[a] array, we will have b strings and longest length in the zero index.\n* We define worst possible res(ult) as "".join(A) where every string in A appended and store it in array for glo...
6
4
[]
2
find-the-shortest-superstring
BFS + PriorityQueue is all you need
bfs-priorityqueue-is-all-you-need-by-her-yqob
If you cannot understand this method, look at lc 847 and lc 743\nlc 847 will tell you what the state means in this problem\nlc 743 will tell you how to use Prio
Hernie8189
NORMAL
2020-07-24T04:58:12.516501+00:00
2020-07-24T04:58:12.516556+00:00
1,038
false
If you cannot understand this method, look at lc 847 and lc 743\nlc 847 will tell you what the state means in this problem\nlc 743 will tell you how to use PriorityQueue to find shortest path in graph with weights\n\n"We may assume that no string in A is substring of another string in A" \nWhich means in Path A-B-C-D\u...
5
2
['Breadth-First Search', 'Java']
0
find-the-shortest-superstring
JavaScript Solution
javascript-solution-by-hiitsherby-3x10
I used similiar technic as 1066. Campus Bike II. If you haven\'t done it, I recommend you to attempt it first.\n\nAnd This Article is my lifesaver as I\'m reall
hiitsherby
NORMAL
2019-07-08T16:54:50.159814+00:00
2019-07-08T16:54:50.159874+00:00
572
false
I used similiar technic as [1066. Campus Bike II](https://leetcode.com/problems/campus-bikes-ii/). If you haven\'t done it, I recommend you to attempt it first.\n\nAnd [This Article](https://medium.com/free-code-camp/unmasking-bitmasked-dynamic-programming-25669312b77b#c94f) is my lifesaver as I\'m really shit at bit m...
5
0
['Dynamic Programming', 'JavaScript']
0
find-the-shortest-superstring
Shortest Path Problem (Directed acyclic graph with nonnegative weights)
shortest-path-problem-directed-acyclic-g-zstf
Treat (last word, used words bitmask) as a node, then\n\nd((i, mska), (j, mskb)) = len(j) - overlap(i,j) if (mska | (1<<j) == mskb) and (mska & (1<<j) == 0) and
yangzhenjian
NORMAL
2018-11-23T05:24:47.168767+00:00
2018-11-23T05:24:47.168822+00:00
20,926
false
Treat (last word, used words bitmask) as a node, then\n```\nd((i, mska), (j, mskb)) = len(j) - overlap(i,j) if (mska | (1<<j) == mskb) and (mska & (1<<j) == 0) and (mska & (1<<i) != 0)\n else INF\n```\nAnd add 2 extra nodes S and T:\n```\nd(S, (i, 1<<i)) = len(i)\nd((i, ALL_NODES), T) = 0\n(0 ...
5
0
[]
1
find-the-shortest-superstring
java dp with bitmask o(12 * 2^12 * 12). easy to explain and impl in 20mins. cheers!
java-dp-with-bitmask-o12-212-12-easy-to-vziq5
\nimport java.util.*;\nimport java.io.*;\n\nclass State {\n int i;\n int state;\n \n State(int i, int state) {\n this.i = i;\n this.st
solaaoi
NORMAL
2018-11-19T08:49:23.265891+00:00
2018-11-19T08:49:23.265933+00:00
1,501
false
```\nimport java.util.*;\nimport java.io.*;\n\nclass State {\n int i;\n int state;\n \n State(int i, int state) {\n this.i = i;\n this.state = state;\n }\n}\n\nclass Solution {\n private PrintStream out = System.out;\n\n private int overlap(String a, String b) {\n int res = 0;\...
5
0
[]
3
find-the-shortest-superstring
Java solution with memorization
java-solution-with-memorization-by-self_-qyen
```\n/ the used array indicates which word is avaible, used[i] == \'1\', means the word is available...\n * map record the pairs, means the shortest string we
self_learner
NORMAL
2018-11-18T04:15:59.267247+00:00
2018-11-18T04:15:59.267321+00:00
1,561
false
```\n/* the used array indicates which word is avaible, used[i] == \'1\', means the word is available...\n * map record the <used array, shortest string> pairs, means the shortest string we can get using the remaining words..\n */\nclass Solution { \n public String shortestSuperstring(String[] A) {\n int n = ...
5
3
[]
1
find-the-shortest-superstring
[Java] Recursion + Memoization + Optimal Path Reconstruction
java-recursion-memoization-optimal-path-vsyku
Top voted solutions are mostly iterative. This is an example of how you can construct an optimal path with a recursive dp solution. In the path reconstruction f
nirvana_rsc
NORMAL
2021-05-26T11:17:28.009831+00:00
2021-05-26T11:17:28.009875+00:00
419
false
Top voted solutions are mostly iterative. This is an example of how you can construct an optimal path with a recursive dp solution. In the path reconstruction function we can begin from the same start state and at each step follow (the already precalculated) best move - in this case the minimum final string length.\n\n...
4
0
[]
0
find-the-shortest-superstring
Easy Understand Java code using Dijsktra
easy-understand-java-code-using-dijsktra-f6om
\nclass Solution {\n class State {\n String word;\n int mask;\n\n public State(String word, int mask) {\n this.word = word;\n
paul_f
NORMAL
2019-09-14T23:48:20.653282+00:00
2019-09-14T23:48:20.653340+00:00
997
false
```\nclass Solution {\n class State {\n String word;\n int mask;\n\n public State(String word, int mask) {\n this.word = word;\n this.mask = mask;\n }\n\n }\n\n public String shortestSuperstring(String[] A) {\n PriorityQueue<State> pq = new PriorityQueue...
4
1
[]
3
find-the-shortest-superstring
C++ 20 line solution, O(n^2*2^n), Concise. Big Money.
c-20-line-solution-on22n-concise-big-mon-bxtw
A variant of the others, not original idea and I tried my best to make it shorter without hampering readability. \nThe vector<vector<string>> can be replaced by
gaaaarbage
NORMAL
2019-01-05T17:20:19.846166+00:00
2019-01-05T17:20:19.846244+00:00
667
false
A variant of the others, not original idea and I tried my best to make it shorter without hampering readability. \nThe `vector<vector<string>>` can be replaced by `vector<vector<int>> index` of word and a `vector<vector<int>> lengthsofar` that counts the current shortest length of the string that was formed with the bi...
4
0
[]
0
find-the-shortest-superstring
NP-hard, use memoization (Oh thank god!)
np-hard-use-memoization-oh-thank-god-by-ymafu
Here is my solution, time complexity should be O(n^3 * (2^n)), use (1 << n) array to memoize the visited states( i.e. which strings have been included)\n\npubli
xuhuiwang
NORMAL
2018-11-18T06:05:03.220511+00:00
2018-11-18T06:05:03.220581+00:00
3,297
false
Here is my solution, time complexity should be O(n^3 * (2^n)), use (1 << n) array to memoize the visited states( i.e. which strings have been included)\n```\npublic class Solution {\n private int n;\n private String[] a;\n public String shortestSuperstring(String[] A) {\n n = A.length;\n a = A;\n...
4
1
[]
2
find-the-shortest-superstring
✅ Easy Self Explanatory Code ✅ - Simple Bitmask DP + Retracing
easy-self-explanatory-code-simple-bitmas-ygkr
\n# Code\n\nclass Solution {\nprivate:\n int n, finalMask;\n int best;\n int dp[12][1 << 12];\n int nextt[12][1 << 12];\n // to find max number o
kingsman007
NORMAL
2023-10-21T15:29:58.428030+00:00
2023-10-21T15:29:58.428047+00:00
643
false
\n# Code\n```\nclass Solution {\nprivate:\n int n, finalMask;\n int best;\n int dp[12][1 << 12];\n int nextt[12][1 << 12];\n // to find max number of common character in two string\n int common(const string& s1 , const string& s2) {\n int i = 1;\n int ans = 0;\n while(i <= s1.size...
3
0
['String', 'Dynamic Programming', 'Memoization', 'Bitmask', 'C++']
1
find-the-shortest-superstring
PreCompute + BitMask + DP || C++
precompute-bitmask-dp-c-by-eghost08-kgfm
\n# Code\n\nclass Solution {\npublic:\n string solve(int last,int mask,int &n,map<int,map<int,int>>&mp,vector<string>&words,vector<vector<string>>&dp){\n
EGhost08
NORMAL
2023-09-24T06:12:25.299135+00:00
2023-09-24T06:12:25.299152+00:00
523
false
\n# Code\n```\nclass Solution {\npublic:\n string solve(int last,int mask,int &n,map<int,map<int,int>>&mp,vector<string>&words,vector<vector<string>>&dp){\n if(mask==((1<<n)-1)){\n return "";\n }\n if(dp[last+1][mask]!="")\n return dp[last+1][mask];\n string curr="";...
3
0
['C++']
1
find-the-shortest-superstring
Java | Held Karp (TSP) | Concise w/ explanations!
java-held-karp-tsp-concise-w-explanation-vnvu
Foreword\nI think this problem is a bit hard because there was a bug in my code that took me hours to catch.\nIt was a silly bug but it does test you on whether
Student2091
NORMAL
2022-07-14T08:21:35.282221+00:00
2022-07-15T08:11:12.513639+00:00
805
false
#### Foreword\nI think this problem is a bit hard because there was a bug in my code that took me hours to catch.\nIt was a silly bug but it does test you on whether you really understand the Held Karp DP to solve TSP.\nMy suffering has just ended! \n\nIt is hard to imagine this question only got a rating of 21xx on ht...
3
0
['Dynamic Programming', 'Java']
0
find-the-shortest-superstring
Python3 - memoization with bitmask, clean solution
python3-memoization-with-bitmask-clean-s-m9kt
The idea is simple: first, let\'s store the overlapping for each pair of words. Second, for DP, during each iteration, we look at words[i]; we need to find a un
yunqu
NORMAL
2021-04-16T01:46:22.654844+00:00
2021-04-16T01:48:06.245229+00:00
385
false
The idea is simple: first, let\'s store the overlapping for each pair of words. Second, for DP, during each iteration, we look at words[i]; we need to find a unused words[j] and consider to merge the two words together. \n\nFor example, words[i] is \'abcde\' and words[j] is \'cdef\', the merging of the two words will b...
3
1
[]
0
find-the-shortest-superstring
C# simple DP solution with explanations. Beats 100%.
c-simple-dp-solution-with-explanations-b-wcz6
\npublic class Solution {\n public string ShortestSuperstring(string[] words) {\n var memo = new Dictionary<string, string>();\n \n // m
attila201805
NORMAL
2021-03-24T20:49:29.113930+00:00
2021-03-24T20:50:18.114885+00:00
312
false
```\npublic class Solution {\n public string ShortestSuperstring(string[] words) {\n var memo = new Dictionary<string, string>();\n \n // mark every word as unused\n int unused = 0; // integer is used as a bit array\n for(int i = 0; i < words.Length; i++) {\n unused |= ...
3
0
[]
0
find-the-shortest-superstring
Travelling Salesman Problem python
travelling-salesman-problem-python-by-an-axgw
\nfrom functools import lru_cache #This is used in order to avoid TLE by implementing memoization\n\nclass Solution:\n def shortestSuperstring(self, words):\
ANiSh684
NORMAL
2024-05-16T15:39:48.311843+00:00
2024-05-16T15:39:48.311865+00:00
382
false
```\nfrom functools import lru_cache #This is used in order to avoid TLE by implementing memoization\n\nclass Solution:\n def shortestSuperstring(self, words):\n def makeadj(words):\n l = len(words)\n adj = [["" for z in range(l)] for x in range(l)]\n for i in range(l):\n ...
2
0
['Bit Manipulation', 'Bitmask', 'Python', 'Python3']
0
find-the-shortest-superstring
DP Bitmask (Iterative/Bottom Up) (TSP)
dp-bitmask-iterativebottom-up-tsp-by-pol-ad0q
Intuition\nThis problem is analogous to the travelling salesman problem, as we need to start from any one string and visit all other strings, such that the tota
polaris01
NORMAL
2023-08-18T08:14:43.278956+00:00
2023-08-18T08:14:43.278995+00:00
236
false
# Intuition\nThis problem is analogous to the travelling salesman problem, as we need to start from any one string and visit all other strings, such that the total length is minimum.\n\n# Approach\nWe can create a state as `(mask, curr_node)`. The `mask` represents the set of visited nodes, and we are currently at `cur...
2
0
['Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'C++']
0
find-the-shortest-superstring
Solution
solution-by-deleted_user-il4w
C++ []\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& A) {\n int dp[4096][12] = {0};\n int failure[12][20] = {0};\n
deleted_user
NORMAL
2023-05-15T02:00:32.897737+00:00
2023-05-15T03:14:36.709638+00:00
1,416
false
```C++ []\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& A) {\n int dp[4096][12] = {0};\n int failure[12][20] = {0};\n int cost[12][12] = {0};\n int trace_table[4096][12] = {0};\n const int sz = A.size();\n const int dp_sz = 1 << sz;\n \n ...
2
0
['C++', 'Java', 'Python3']
0
find-the-shortest-superstring
Find the Shortest Superstring Bugs? | Python
find-the-shortest-superstring-bugs-pytho-aoo8
Is there a bug in the leetcode submitting system for this problem? How is this getting accepted?\n\n\nBy the way here is a serious code if you are looking for i
Interstigation
NORMAL
2021-05-23T16:37:51.990329+00:00
2021-05-23T16:38:49.013436+00:00
398
false
Is there a bug in the leetcode submitting system for this problem? How is ***this*** getting accepted?\n![image](https://assets.leetcode.com/users/images/d4aa48e6-eaa4-4438-9ac2-ff6d0b28dcf6_1621787863.1228492.png)\n\nBy the way here is a serious code if you are looking for it\n```\nclass Solution:\n def shortestSup...
2
2
[]
1
find-the-shortest-superstring
Swift solution (Travelling Salesman Problem)
swift-solution-travelling-salesman-probl-ih50
Swift version of https://leetcode.com/problems/find-the-shortest-superstring/discuss/194932/Travelling-Salesman-Problem\n\nclass Solution {\n func shortestSu
yamironov
NORMAL
2021-05-23T16:07:32.808358+00:00
2021-05-23T19:12:33.542582+00:00
166
false
Swift version of https://leetcode.com/problems/find-the-shortest-superstring/discuss/194932/Travelling-Salesman-Problem\n```\nclass Solution {\n func shortestSuperstring(_ words: [String]) -> String {\n let n = words.count, n2 = 1 << n\n\n // build the graph\n var graph = [[Int]](repeating: [Int...
2
0
['Swift']
1
find-the-shortest-superstring
C++ recursion and memoization
c-recursion-and-memoization-by-jeeteqxyz-vvzu
```\nclass Solution {\npublic:\n vectorlen;\n vector>overlap;\n vector>dp;\n int n;\n map, int>mp;\n int solve(int idx, int mask){\n if
jeeteqxyz
NORMAL
2020-10-08T11:32:00.969496+00:00
2020-10-08T11:32:00.969535+00:00
469
false
```\nclass Solution {\npublic:\n vector<int>len;\n vector<vector<int>>overlap;\n vector<vector<int>>dp;\n int n;\n map<pair<int, int>, int>mp;\n int solve(int idx, int mask){\n if(mask == (1 << n) - 1) return 0;\n if(dp[idx][mask] != -1)return dp[idx][mask];\n dp[idx][mask] = INT_...
2
1
[]
2
find-the-shortest-superstring
C++ O(N^2 * 2^N) Bitmask DP + DFS solution w/ explanation
c-on2-2n-bitmask-dp-dfs-solution-w-expla-6pwz
The idea is that after selecting some words, we have to find the minimum length of the remaining superstring. For that we check all the remaining words. The sel
varkey98
NORMAL
2020-08-14T11:22:56.373920+00:00
2020-08-14T11:23:19.886144+00:00
929
false
The idea is that after selecting some words, we have to find the minimum length of the remaining superstring. For that we check all the remaining words. The selected words are marked by the bitmask. After finding the minimum length, simply run an O(N^2) DFS for finding the answer.\n```\nint min(int a,int b)\n{\n ret...
2
1
['Dynamic Programming', 'Depth-First Search', 'C', 'Bitmask']
0
find-the-shortest-superstring
C++ solution using DP with memoization (Beats 90% in runtime)
c-solution-using-dp-with-memoization-bea-bvi8
\nvector<vector<int> > dp,pre,par;\n\nbool startWith(string s, string t)\n{\n// returns true if string s starts with string t\n int i;\n for(i=0; i<s.leng
cjchirag7
NORMAL
2020-08-08T09:26:13.906636+00:00
2020-08-08T09:26:13.906667+00:00
1,400
false
```\nvector<vector<int> > dp,pre,par;\n\nbool startWith(string s, string t)\n{\n// returns true if string s starts with string t\n int i;\n for(i=0; i<s.length()&&i<t.length(); i++)\n {\n if(s[i]==t[i])\n continue;\n else\n return false;\n }\n if(i==t.length())\n ...
2
1
['Dynamic Programming', 'Memoization', 'C', 'C++']
0
find-the-shortest-superstring
Java Graph, TSP and DP
java-graph-tsp-and-dp-by-hobiter-8qno
1, build a directed graph, where edge values are cost to concate from string to next string;\n2, find 1 route from the graph to\na, include all nodes once and o
hobiter
NORMAL
2020-06-06T23:49:20.776991+00:00
2020-06-06T23:49:20.777041+00:00
407
false
1, build a directed graph, where edge values are cost to concate from string to next string;\n2, find 1 route from the graph to\na, include all nodes once and only once;\nb, make sure the cost are the minmum;\n\nFrom the above 2, it is the defination similar to TSP (Travelling Salesman Problem);\nRef https://leetcode.c...
2
0
[]
0
find-the-shortest-superstring
Python3 - Top Down BitMask DP
python3-top-down-bitmask-dp-by-havingfun-q965
As the question mentions that no string in A will be substring of another string in A. I can conclude that we can find our answer by one of the permutations of
havingfun
NORMAL
2020-06-03T05:27:17.633181+00:00
2020-06-03T05:27:17.633213+00:00
243
false
As the question mentions that no string in A will be substring of another string in A. I can conclude that we can find our answer by one of the permutations of combining different strings in A. If you combine two strings in A - like a + b, you can count the largest suffix of a which is also prefix of b. So I have a hel...
2
0
[]
0
find-the-shortest-superstring
[Java] Bitmask DP Solution
java-bitmask-dp-solution-by-frenkiedejon-c7ok
dp[i][mask] represents the shortest superstring which ends at i-th word (A[i]), participating words are denoted by mask, for example, mask 0b01011 means partici
frenkiedejong
NORMAL
2020-01-02T05:10:57.221630+00:00
2020-01-02T05:15:33.790120+00:00
392
false
* dp[i][mask] represents the shortest superstring which ends at *i-th* word (A[i]), participating words are denoted by mask, for example, mask 0b01011 means participating words are A[0], A[1], A[3]\n* My DP transition function stores the String directly, so I don\'t need to construct the resulting string at the end\n\t...
2
0
[]
0
find-the-shortest-superstring
[Inefficient Java solution] DFS - Beat 5%
inefficient-java-solution-dfs-beat-5-by-tm9u5
\nclass Solution {\n private static class Result {\n String value = "";\n }\n \n public String shortestSuperstring(String[] A) {\n if
zacling
NORMAL
2019-07-29T23:54:02.563444+00:00
2019-07-29T23:54:02.563481+00:00
344
false
```\nclass Solution {\n private static class Result {\n String value = "";\n }\n \n public String shortestSuperstring(String[] A) {\n if (A.length == 1) return A[0];\n \n int[][] subAt = new int[A.length][A.length];\n for (int i = 0; i < A.length; ++i)\n for (in...
2
0
[]
1
find-the-shortest-superstring
C++ Recursive Dp + Path Finding ~20 ms
c-recursive-dp-path-finding-20-ms-by-emi-r47r
I try to maximise the overlap length in the salesman\'s total path.\n\n#define se second\n#define fi first\n#define dbg(x) cout<<#x<<" = "<<(x)<<endl;\n#define
eminem347
NORMAL
2018-11-20T07:49:18.906602+00:00
2018-11-20T07:49:18.906642+00:00
700
false
I try to maximise the overlap length in the salesman\'s total path.\n```\n#define se second\n#define fi first\n#define dbg(x) cout<<#x<<" = "<<(x)<<endl;\n#define dbg1(x,y) cout<<#x<<" = "<<(x)<<" | "<<#y<<" = "<<(y)<<endl;\ntypedef pair<int,int> ii;\ntypedef pair<int,ii> iii;\ntypedef vector<int> vi;\ntypedef vector<v...
2
0
[]
0
find-the-shortest-superstring
Simple approach (C++) Solution
simple-approach-c-solution-by-harrypotte-uswc
\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& A) {\n int n=A.size(),m=0,i,j,k,o,a[12][12],l[12],p[12],f[4096][12];\n
harrypotter0
NORMAL
2018-11-18T04:15:27.995848+00:00
2018-11-18T04:15:27.995896+00:00
807
false
```\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& A) {\n int n=A.size(),m=0,i,j,k,o,a[12][12],l[12],p[12],f[4096][12];\n for(i=0;i<n;i++)l[i]=A[i].size();\n memset(f,0,sizeof(f));\n for(i=0;i<n;i++)for(j=0;j<n;j++)if(i!=j)for(a[i][j]=0,k=1;k<l[i]&&k<l[j];k++)\n ...
2
2
[]
3
find-the-shortest-superstring
Easy to understand TSP implementation (Top-Down/Bottom-Up)[python]
easy-to-understand-tsp-implementation-to-kxng
Approach\n Describe your approach to solving the problem. \nConsider this problem as a graph problem where we need to visit every single node with the minimal o
vgnshiyer
NORMAL
2023-10-17T18:14:00.716606+00:00
2023-10-17T18:14:00.716637+00:00
167
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nConsider this problem as a graph problem where we need to visit every single node with the minimal overall cost. The words will be our nodes and the nonOverlapping substring between two words will be our cost.\n\n# Complexity\n- Time complexity:\n<!--...
1
0
['Bit Manipulation', 'Graph', 'Bitmask', 'Python3']
0
find-the-shortest-superstring
C++ Basic recursion + memoization - Travelling salesman Problem approach:
c-basic-recursion-memoization-travelling-gdmd
Intuition\n Describe your first thoughts on how to solve this problem. \nIf we can consider the overlapping among the strings as weights . then we can translate
280iva
NORMAL
2023-10-02T15:42:30.448994+00:00
2023-10-02T15:42:30.449023+00:00
126
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we can consider the overlapping among the strings as weights . then we can translate the problem as find the order of the strings with maximum sum weight or maximum overlapping. \ni.e travel all the nodes in maximum weight \n# Approach...
1
0
['C++']
0
find-the-shortest-superstring
Esay C++ Sol 🔥🔥
esay-c-sol-by-rishu_raj_10042002-t7w7
Code\n\nclass Solution {\npublic:\n \n string addFront(string a,string b)\n {\n int n1 = a.length();\n int n2 = b.length();\n stri
rishu_raj_10042002
NORMAL
2023-09-12T17:02:29.206754+00:00
2023-09-12T17:02:29.206787+00:00
599
false
# Code\n```\nclass Solution {\npublic:\n \n string addFront(string a,string b)\n {\n int n1 = a.length();\n int n2 = b.length();\n string ans = "";\n for(int i=b.length()-1;i>=0;i--)\n {\n int len = 0;\n \n int i1 = i;\n int i2 = 0...
1
0
['C++']
2
find-the-shortest-superstring
C++ | DP + BFS | Cleaner than official
c-dp-bfs-cleaner-than-official-by-lowkey-xb60
Intuition\n Describe your first thoughts on how to solve this problem. \nVery hard problem for mortals and probably will not be on interview but worth doing to
lowkeyandgrace
NORMAL
2023-02-11T19:10:58.767932+00:00
2023-02-11T19:11:27.133278+00:00
412
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nVery hard problem for mortals and probably will not be on interview but worth doing to improve skills and expand DP understanding.\n\nNot immediately obviously that it\'s DP problem. We want build word paths with help of memoize (dp) of b...
1
0
['C++']
0
find-the-shortest-superstring
[python] dp + bitmask
python-dp-bitmask-by-vl4deee11-4p3r
\nclass Solution:\n def shortestSuperstring(self, words: List[str]) -> str:\n rbm=[0]\n for i in range(len(words)):rbm[0]|=(1<<i)\n def
vl4deee11
NORMAL
2022-11-11T05:02:38.520937+00:00
2022-11-11T05:03:43.652362+00:00
111
false
```\nclass Solution:\n def shortestSuperstring(self, words: List[str]) -> str:\n rbm=[0]\n for i in range(len(words)):rbm[0]|=(1<<i)\n def isc(prev,curr):\n i=0\n i2=0\n mi2=0\n while i<len(prev):\n i1=i\n while i1<len(pre...
1
0
[]
0
find-the-shortest-superstring
C++|Clean DP solution
cclean-dp-solution-by-endless_mercury-5iwe
Breaking stereotype of using dp for storing only integers or boolean.\nSimple Solution using bitmask dp and trying all combinations\n\nclass Solution {\npublic:
endless_mercury
NORMAL
2022-10-29T11:19:33.269350+00:00
2022-10-29T11:19:33.269393+00:00
301
false
Breaking stereotype of using dp for storing only integers or boolean.\nSimple Solution using bitmask dp and trying all combinations\n```\nclass Solution {\npublic:\n string solve(int last,int mask,int n,int need,map<int,map<int,int>>&mp,vector<string>&words,vector<vector<string>>&dp){\n if(mask==need){\n ...
1
0
['Dynamic Programming', 'C']
2
find-the-shortest-superstring
klickh baith soluution
klickh-baith-soluution-by-utkarsh190-k8oa
"When you meet your God tell him to leave me alone" - Guts\n\nclass Solution {\nprivate:\n int calcOverlap(string a, string b){\n if(a == "" || b == "
utkarsh190
NORMAL
2022-05-17T17:48:30.710453+00:00
2022-05-17T17:48:30.710501+00:00
139
false
"When you meet your God tell him to leave me alone" - Guts\n```\nclass Solution {\nprivate:\n int calcOverlap(string a, string b){\n if(a == "" || b == "") return 0;\n int n = a.length();\n for(int len = min(a.length()-1, b.length()-1); len >= 0; len--){\n bool found = true;\n ...
1
0
[]
0
find-the-shortest-superstring
Python | TSP | Simple Code with Bit Mask
python-tsp-simple-code-with-bit-mask-by-bk6q2
bitmask: contains information of nodes that are visited currently\ndfs(bitmask, i): shortest superstring after i with visited nodes bitmask\n```\nclass Solution
aryonbe
NORMAL
2022-04-13T06:17:00.010830+00:00
2022-04-22T10:46:55.086478+00:00
408
false
bitmask: contains information of nodes that are visited currently\ndfs(bitmask, i): shortest superstring after i with visited nodes bitmask\n```\nclass Solution:\n def shortestSuperstring(self, A):\n @lru_cache(None)\n def suffix(i,j):\n for k in range(min(len(A[i]),len(A[j])),0,-1):\n ...
1
0
['Bit Manipulation', 'Python']
0
find-the-shortest-superstring
Java Bitmask DP
java-bitmask-dp-by-zerocool1989-kfd8
This is a varaint of the travelling salesman problem.\n\n\nclass Solution {\n \n public String shortestSuperstring(String[] words) {\n String[][] t
zerocool1989
NORMAL
2021-10-10T17:00:30.223275+00:00
2021-10-10T17:00:30.223314+00:00
175
false
This is a varaint of the travelling salesman problem.\n\n```\nclass Solution {\n \n public String shortestSuperstring(String[] words) {\n String[][] toAdd = new String[words.length][words.length];\n String[][] dp = new String[words.length + 1][(1 << (words.length + 1))];\n\n for (int i = 0; i...
1
0
[]
0
find-the-shortest-superstring
Easy Recursive Solution in Java Using DP Bitmask
easy-recursive-solution-in-java-using-dp-k7mn
I have used recursive memoized approach as the iterative appraoch would be hard to understand. Similar to TSP Problem.\nThe first call is to a dummy node.\n\n``
rite2riddhi
NORMAL
2021-08-10T04:38:12.372393+00:00
2021-08-10T04:38:51.210766+00:00
355
false
I have used recursive memoized approach as the iterative appraoch would be hard to understand. Similar to TSP Problem.\nThe first call is to a dummy node.\n\n```class Solution {\n private String dp[][];\n private int n;\n private int [][] graph;\n \n private int overlap(String word1 , String word2)\n ...
1
0
[]
1
find-the-shortest-superstring
Java using dp bitmask beats 97%
java-using-dp-bitmask-beats-97-by-julian-vg8x
\nclass Solution {\n public String shortestSuperstring(String[] words) { \n int n = words.length;\n int[][] cost = buildGraph(words); // runti
julianzheng
NORMAL
2021-07-11T06:12:41.041040+00:00
2021-07-11T06:12:41.041086+00:00
248
false
```\nclass Solution {\n public String shortestSuperstring(String[] words) { \n int n = words.length;\n int[][] cost = buildGraph(words); // runtime O(N^2 * L^2)\n \n // dp[i][j]: the minimal cost to get to state i with words[j] as the last word\n int[][] dp = new int[1 << n][n];\n...
1
0
[]
0
find-the-shortest-superstring
javascript use graph + bitmask dp
javascript-use-graph-bitmask-dp-by-henry-iw2b
reference:\nhttps://leetcode.com/problems/find-the-shortest-superstring/discuss/195487/python-bfs-solution-with-detailed-explanation(with-extra-Chinese-explanat
henrychen222
NORMAL
2021-05-26T21:03:27.476808+00:00
2021-05-26T23:21:20.590960+00:00
257
false
reference:\nhttps://leetcode.com/problems/find-the-shortest-superstring/discuss/195487/python-bfs-solution-with-detailed-explanation(with-extra-Chinese-explanation)\nTLE fixed by @fdglchen\nhttps://leetcode.com/problems/find-the-shortest-superstring/discuss/195487/python-bfs-solution-with-detailed-explanation(with-extr...
1
0
['Graph', 'Bitmask', 'JavaScript']
0
find-the-shortest-superstring
(C++) 943. Find the Shortest Superstring
c-943-find-the-shortest-superstring-by-q-272u
top-down\n\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& words) {\n int n = size(words); \n vector<vector<int>> ovlp(
qeetcode
NORMAL
2021-05-26T15:31:01.887441+00:00
2021-05-26T19:51:03.776997+00:00
895
false
**top-down**\n```\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& words) {\n int n = size(words); \n vector<vector<int>> ovlp(n, vector<int>(n, 0)); \n \n for (int i = 0; i < n; ++i) \n for (int j = 0; j < n; ++j) \n for (int k = 0; k < mi...
1
1
['C']
1