what an explanation :) ,from brute force to optimized , just loved it 🙌
@jayantsharma39686 ай бұрын
Great explanation!
@miketsubasa36116 ай бұрын
Excellent Explanation
@NeerajSharma-mz4es7 ай бұрын
nice solution explanation
@ujjwalagnihotri50013 ай бұрын
TOP notch content
@prithwirajmitra38118 ай бұрын
Best explanation. Especially O(N^4) part
@visheshmittal99858 ай бұрын
Loved the detailed explanation. Really helpful in building the intuition from scratch. Thankyou for the efforts. Keep it up!! 💯
@Cools748 ай бұрын
Any hint for today leetcode problem D
@codingmohan8 ай бұрын
Haven't solved it yet. Will check in sometime.
@ankurb078 ай бұрын
It's a simple multiset prob
@PriyanshuGautam-v6e8 ай бұрын
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
@codingmohan8 ай бұрын
Because you don't have "diff" inside your state, you need to reset your "dp" array for every "diff" you are calculating for.