3098. Find the Sum of Subsequence Powers | Leetcode Biweekly 127

  Рет қаралды 733

codingMohan

codingMohan

Күн бұрын

Пікірлер: 14
@Susindran.K
@Susindran.K 8 ай бұрын
what an explanation :) ,from brute force to optimized , just loved it 🙌
@jayantsharma3968
@jayantsharma3968 6 ай бұрын
Great explanation!
@miketsubasa3611
@miketsubasa3611 6 ай бұрын
Excellent Explanation
@NeerajSharma-mz4es
@NeerajSharma-mz4es 7 ай бұрын
nice solution explanation
@ujjwalagnihotri5001
@ujjwalagnihotri5001 3 ай бұрын
TOP notch content
@prithwirajmitra3811
@prithwirajmitra3811 8 ай бұрын
Best explanation. Especially O(N^4) part
@visheshmittal9985
@visheshmittal9985 8 ай бұрын
Loved the detailed explanation. Really helpful in building the intuition from scratch. Thankyou for the efforts. Keep it up!! 💯
@Cools74
@Cools74 8 ай бұрын
Any hint for today leetcode problem D
@codingmohan
@codingmohan 8 ай бұрын
Haven't solved it yet. Will check in sometime.
@ankurb07
@ankurb07 8 ай бұрын
It's a simple multiset prob
@PriyanshuGautam-v6e
@PriyanshuGautam-v6e 8 ай бұрын
Hello sir, this is my code without memoization. It's giving TLE , but I haven't been able to implement memoization yet. I've been trying for a day now. Could you please help me by making changes to my code or providing some guidance to fix my solution? "After implementing memoization, the code produces incorrect output" int dp[55][55][2501]; int fxn(int i, int prev, int n, vector&nums, int k, int dif) { if (i == n) { return (k == 0); } // if (dp[i][prev + 1][k] != -1) return dp[i][prev + 1][k]; // Check if value is already computed int ans = 0; ans += fxn(i + 1, prev, n, nums, k, dif); if (prev == -1) { ans += fxn(i + 1, i, n, nums, k - 1, dif); } else if (nums[i] - nums[prev] >= dif) { ans += fxn(i + 1, i, n, nums, k - 1, dif); } return ans; // Memoize the result before returning } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int k; cin >> k; vectornums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; } sets; sort(nums.begin(), nums.end()); for (int i = 0; i < nums.size(); i++) { for (int j = i + 1; j < nums.size(); j++) { s.insert(-1 * abs(nums[i] - nums[j])); } } int ans = 0; int prevCnt = 0; memset(dp, -1, sizeof(dp)); // Initialize dp array with -1 for (auto &i : s) { int dif = abs(i); int cnt = fxn(0, -1, nums.size(), nums, k, dif); cout
@codingmohan
@codingmohan 8 ай бұрын
Because you don't have "diff" inside your state, you need to reset your "dp" array for every "diff" you are calculating for.
@PriyanshuGautam-v6e
@PriyanshuGautam-v6e 7 ай бұрын
@@codingmohan Thank you, sir, it worked 🛐
3102. Minimize Manhattan Distances | Weekly Leetcode 391
25:13
2926. Maximum Balanced Subsequence Sum |  Weekly Leetcode 370
39:28
codingMohan
Рет қаралды 1,8 М.
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 248 МЛН
First Contest Solution 2024-2025
1:08:23
JUST ACM Student Chapter
Рет қаралды 1,1 М.
3086. Minimum Moves to Pick K Ones | Weekly Leetcode 389
56:34
codingMohan
Рет қаралды 1,3 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
3219. Minimum Cost for Cutting Cake II | Weekly Leetcode 406
1:03:26
3351. Sum of Good Subsequences | DP | Don't Overthink here :)
14:38
Aryan Mittal
Рет қаралды 2,3 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 200 М.
3093. Longest Common Suffix Queries | Weekly Leetcode 390
42:23