codingMohan
codingMohan
  • 371
  • 453 297
3287. Find the Maximum Sequence Value of Array | Leetcode Biweekly 139
Segment Tree Series - bit.ly/segment-trees
*************************************************
Contest Link - leetcode.com/contest/biweekly-contest-139/
Problem Link - leetcode.com/contest/biweekly-contest-139/problems/find-the-maximum-sequence-value-of-array/description/
Solution - leetcode.com/problems/find-the-maximum-sequence-value-of-array/solutions/5790538/video-explanation-dissecting-problem-step-by-step-with-intuition-why-not-recursion/
*************************************************
Timestamps -
00:00 - Agenda
00:45 - Problem Description
02:06 - Brute Force solution
02:39 - Simplifying the problem
10:00 - IsPossible (l_or, r_or, k) -- Simplifying definition
14:50 - IsPossible (or, k) -- Why recursion doesn't work?
19:05 - IsPossible (or) -- Enumerating all possible "OR" value
21:35 - IsPossible (or) -- Dry run of Algorithm
29:45 - Recap of complete Algorithm so-far
31:25 - IsPossible (or, k) -- Min elements required for given "or"
41:33 - IsPossible (or, k) -- Pseudo code
45:00 - IsPossible (or, k) -- Quick Recap of complete Algorithm
46:50 - Time Complexity
47:52 - Code Walkthrough
*************************************************
Interview Experiences Playlists -
Microsoft - th-cam.com/play/PL9TOCZErLZcOsCBZPQ3uIMzak6gQWG_Kp.html
Amazon - th-cam.com/play/PL9TOCZErLZcMFSmxoEpNBxvQfWOgRmsfX.html
D.E.Shaw - th-cam.com/play/PL9TOCZErLZcM8nwVeW4d7JyxcpH175IZ1.html
Linkedin - th-cam.com/play/PL9TOCZErLZcMN56ITB1IkNUs10QnaEyAe.html
Facebook - th-cam.com/play/PL9TOCZErLZcNIcaPV8WeHdXHPgAstBf2E.html
*********************************************************************
Please show support and subscribe if you find the content useful.
มุมมอง: 760

วีดีโอ

3291. Minimum Number of Valid Strings to Form Target I | Weekly Leetcode 415
มุมมอง 69612 ชั่วโมงที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Contest Link - leetcode.com/contest/weekly-contest-415 Problem Link - leetcode.com/contest/weekly-contest-415/problems/minimum-number-of-valid-strings-to-form-target-i/ Solution - leetcode.com/problems/minimum-number-of-valid-strings-to-form-target-ii/solutions/5789212/video-explanat...
3292. Minimum Number of Valid Strings to Form Target II | Weekly Leetcode 415 | Z-Algorithm
มุมมอง 53512 ชั่วโมงที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees Similar Hashing Problems - 1. th-cam.com/video/8kMq8WyCpj0/w-d-xo.html 2. th-cam.com/video/1thnThrIzwg/w-d-xo.html 3. th-cam.com/video/hRd3ZlTBkEs/w-d-xo.html DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Z-Algorithm - cp-algorithms.com/string/z-function....
3283. Maximum Number of Moves to Kill All Pawns | Weekly Leetcode 414
มุมมอง 651วันที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-414 Problem Link - leetcode.com/contest/weekly-contest-414/problems/maximum-number-of-moves-to-kill-all-pawns/description/ Solution - leetcode.com/problems/ma...
3277. Maximum XOR Score Subarray Queries | Weekly Leetcode 413
มุมมอง 83514 วันที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-413 Problem Link - leetcode.com/contest/weekly-contest-413/problems/maximum-xor-score-subarray-queries/ Solution - leetcode.com/problems/maximum-xor-score-sub...
3276. Select Cells in Grid With Maximum Score | Weekly Leetcode 413
มุมมอง 1.4K14 วันที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-413 Problem Link - leetcode.com/contest/weekly-contest-413/problems/select-cells-in-grid-with-maximum-score/ Solution - leetcode.com/problems/select-cells-in-...
3267. Count Almost Equal Pairs II | Weekly Leetcode 412
มุมมอง 63721 วันที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-412 Problem Link - leetcode.com/contest/weekly-contest-412/problems/count-almost-equal-pairs-ii/ Solution - leetcode.com/problems/count-almost-equal-pairs-ii/...
3266. Final Array State After K Multiplication Operations II | Weekly Leetcode 412
มุมมอง 1.2K21 วันที่ผ่านมา
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-412 Problem Link - leetcode.com/contest/weekly-contest-412/problems/final-array-state-after-k-multiplication-operations-ii/ Solution - leetcode.com/problems/f...
3250. Find the Count of Monotonic Pairs I | Weekly Leetcode 410
มุมมอง 1.4Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link -leetcode.com/contest/weekly-contest-410/problems/find-the-count-of-monotonic-pairs-i/ Solution - leetcode.com/problems/find-the-count-of-mon...
3251. Find the Count of Monotonic Pairs II | Weekly Leetcode 410
มุมมอง 1.9Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees DP Playlist - th-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link -leetcode.com/contest/weekly-contest-410/problems/find-the-count-of-monotonic-pairs-ii/ Solution - leetcode.com/problems/find-the-count-of-mo...
3245. Alternating Groups III | Weekly Leetcode 409
มุมมอง 1.4Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link - leetcode.com/contest/weekly-contest-409/problems/alternating-groups-iii/description/ Solution - leetcode.com/problems/alternating-groups-iii/solutions/5585945/video-explanation-starting-from-brute-force-and-op...
3244. Shortest Distance After Road Addition Queries II | Weekly Leetcode 409
มุมมอง 1.1Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link - leetcode.com/contest/weekly-contest-409/problems/shortest-distance-after-road-addition-queries-ii/description/ Solution - leetcode.com/problems/shortest-distance-after-road-addition-queries-ii/solutions/558407...
3235. Check if the Rectangle Corner Is Reachable | Weekly Leetcode 408
มุมมอง 1.1Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-408 Problem Link - leetcode.com/contest/weekly-contest-408/problems/check-if-the-rectangle-corner-is-reachable/ Solution - leetcode.com/problems/check-if-the-rectangle-corner-is-reachable/solutions/5547478/video-explanation-intu...
3234. Count the Number of Substrings With Dominant Ones | Weekly Leetcode 408
มุมมอง 4.5Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - th-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-408 Problem Link - leetcode.com/contest/weekly-contest-408/problems/count-the-number-of-substrings-with-dominant-ones/ Solution - leetcode.com/problems/count-the-number-of-substrings-with-dominant-ones/solutions/5546880/video-ex...
3225. Maximum Score From Grid Operations | Leetcode Biweekly 135
มุมมอง 1.6Kหลายเดือนก่อน
Segment Tree Series - bit.ly/segment-trees Contest Link - leetcode.com/contest/biweekly-contest-135/ Problem Link - leetcode.com/contest/biweekly-contest-135/problems/maximum-score-from-grid-operations/description/ Solution - leetcode.com/problems/maximum-score-from-grid-operations/solutions/5517272/video-explanation-journey-of-o-r-4-c-o-r-3-c-o-r-r-c/ Timestamps - 00:00 - Agenda 01:09 - Proble...
3229. Minimum Operations to Make Array Equal to Target | Weekly Leetcode 407
มุมมอง 729หลายเดือนก่อน
3229. Minimum Operations to Make Array Equal to Target | Weekly Leetcode 407
3218. Minimum Cost for Cutting Cake I | Weekly Leetcode 406
มุมมอง 4272 หลายเดือนก่อน
3218. Minimum Cost for Cutting Cake I | Weekly Leetcode 406
3219. Minimum Cost for Cutting Cake II | Weekly Leetcode 406
มุมมอง 3852 หลายเดือนก่อน
3219. Minimum Cost for Cutting Cake II | Weekly Leetcode 406
3213. Construct String with Minimum Cost | Weekly Leetcode 405
มุมมอง 1.1K2 หลายเดือนก่อน
3213. Construct String with Minimum Cost | Weekly Leetcode 405
3209. Number of Subarrays With AND Value of K | Leetcode Biweekly 134
มุมมอง 6912 หลายเดือนก่อน
3209. Number of Subarrays With AND Value of K | Leetcode Biweekly 134
3212. Count Submatrices With Equal Frequency of X and Y | Weekly Leetcode 405
มุมมอง 1.2K2 หลายเดือนก่อน
3212. Count Submatrices With Equal Frequency of X and Y | Weekly Leetcode 405
3202. Find the Maximum Length of Valid Subsequence II | Weekly Leetcode 404
มุมมอง 1.4K2 หลายเดือนก่อน
3202. Find the Maximum Length of Valid Subsequence II | Weekly Leetcode 404
3203. Find Minimum Diameter After Merging Two Trees | Weekly Leetcode 404
มุมมอง 5642 หลายเดือนก่อน
3203. Find Minimum Diameter After Merging Two Trees | Weekly Leetcode 404
3197. Find the Minimum Area to Cover All Ones II | Weekly Leetcode 403
มุมมอง 1K2 หลายเดือนก่อน
3197. Find the Minimum Area to Cover All Ones II | Weekly Leetcode 403
3186. Maximum Total Damage With Spell Casting | Weekly Leetcode 402
มุมมอง 8573 หลายเดือนก่อน
3186. Maximum Total Damage With Spell Casting | Weekly Leetcode 402
3187. Peaks in Array | Weekly Leetcode 402
มุมมอง 5653 หลายเดือนก่อน
3187. Peaks in Array | Weekly Leetcode 402
3170. Lexicographically Minimum String After Removing Stars | Weekly Leetcode 400
มุมมอง 4073 หลายเดือนก่อน
3170. Lexicographically Minimum String After Removing Stars | Weekly Leetcode 400
3171. Find Subarray With Bitwise AND Closest to K | 2 different Approaches | Weekly Leetcode 400
มุมมอง 1.2K3 หลายเดือนก่อน
3171. Find Subarray With Bitwise AND Closest to K | 2 different Approaches | Weekly Leetcode 400
3165. Maximum Sum of Subsequence With Non-adjacent Elements | Bonus Qs + Hint | Weekly Leetcode 399
มุมมอง 1.5K3 หลายเดือนก่อน
3165. Maximum Sum of Subsequence With Non-adjacent Elements | Bonus Qs Hint | Weekly Leetcode 399
3164. Find the Number of Good Pairs II | 2 Approaches | Weekly Leetcode 399
มุมมอง 1K3 หลายเดือนก่อน
3164. Find the Number of Good Pairs II | 2 Approaches | Weekly Leetcode 399

ความคิดเห็น

  • @priyanshupriyadarshi502
    @priyanshupriyadarshi502 ชั่วโมงที่ผ่านมา

    Hi Bro, really good content. intuition is clear. I first tried submitting my code similar to yours 1st approach( using hashing ) but got wrong answer at 799/807. After that I submitted your code and faced the same issue. can you pls look into this.

    • @codingmohan
      @codingmohan ชั่วโมงที่ผ่านมา

      They might have updated the test case to introduce collision for the specific hash function we are using. You can just duplicate the hash calculation with different values of P and/or MOD and compare as a pair instead of single value to avoid collision.

    • @codingmohan
      @codingmohan ชั่วโมงที่ผ่านมา

      To be honest, if you are able to reach 799 test cases through your code, you probably understand everything that this approach would teach you and simply move forward to different approach :)

  • @sk45861
    @sk45861 วันที่ผ่านมา

    why do you need to maintain the index in the map value when we can just maintain the minimum value by comparison at real time?

  • @hmmm-v6f
    @hmmm-v6f 2 วันที่ผ่านมา

    best explanation on the internet for this question but the views are so less. I also avoided your video for the last two days because of the thumbnail. I thought content wont be of very good quality but everything was perfect. so maybe put a better thumbnail from the next video... your content is already gold🙏

  • @Aman-r7b
    @Aman-r7b 2 วันที่ผ่านมา

    Sir your way of explanations is just amazing . Everything which you explains goes directly in my head and it helps me in thinking in this way. Thank you so much sir ☺☺

  • @shivamchaudhary7574
    @shivamchaudhary7574 2 วันที่ผ่านมา

    Nice explanation

  • @swastikverma5937
    @swastikverma5937 3 วันที่ผ่านมา

    Awesome explaination

  • @satyamsurya1414
    @satyamsurya1414 3 วันที่ผ่านมา

    very good explanation sir ... so happy to see this....

  • @varungudamsetti449
    @varungudamsetti449 3 วันที่ผ่านมา

    Why cant we just store all the prefixes in a set and have a constant time lookup in the recursive method? In that case TC would be tLen*tLen right? I did the same but it is giving me TLE. Could you please explain why?

    • @codingmohan
      @codingmohan 3 วันที่ผ่านมา

      Inside the for loop you would be doing something like - allPrefixesSet.count(prefix) This is not O(1) operation because for just 1 comparison you would need to iterate over the string. Hence your current complexity is T*T*T. To make this approach work, you would need to hash all your stored prefixes and store the hash in the set. Now while comparing, you will hash the prefix (rolling hash) and search that in the set.

    • @shreyanshkumarsahu6534
      @shreyanshkumarsahu6534 วันที่ผ่านมา

      I also use set for storing prefixes but get MLE

  • @amritpandey6964
    @amritpandey6964 4 วันที่ผ่านมา

    Love your way of explanation.

  • @ziqyeow
    @ziqyeow 4 วันที่ผ่านมา

    bro, I've subscribed, keep doing what you are doing, your channel is literally underrated.

  • @satyamsurya1414
    @satyamsurya1414 4 วันที่ผ่านมา

    what a explnation sir....bhagwan kare aapke channel par 1 million subscribers ho jaye....☺😍

  • @Abhi_008
    @Abhi_008 4 วันที่ผ่านมา

    what if i could generate all the prefixes of given string and store it in set. Then Iterate over target checking if 1,2,3, ... lengths of prefixes are available in set. If yes, then we make reursive call for further length 1,2,3.... This also has an T^2 complexity but giving tle on 916/929? sudo code: int res = INT_MAX; string prefix; for (int j = idx; j < n; j ++) { // iterating over target string prefix += target[j]; if (st.count(prefix)) { // checking in set if prefix are available int nextRec = optimal(words, target, j + 1); if (nextRec != -1) { res = min(res, 1 + nextRec); } } else break; }

    • @varungudamsetti449
      @varungudamsetti449 3 วันที่ผ่านมา

      I did exactly the same and my doubt is also the same.

    • @Abhi_008
      @Abhi_008 3 วันที่ผ่านมา

      @@varungudamsetti449 But dont know why tle? since the time complexity remains only T^2. Right??

    • @codingmohan
      @codingmohan 2 วันที่ผ่านมา

      I tried explaining in another comment above (see the pinned comment).

  • @arjunc1482
    @arjunc1482 4 วันที่ผ่านมา

    Can you do the drawing in dark mode?

  • @NikhilTiwari-to7sv
    @NikhilTiwari-to7sv 4 วันที่ผ่านมา

    we can also precompute a rolling hash using rabin karp algorithm instead of building trie time complexity will remain the same..

    • @codingmohan
      @codingmohan 3 วันที่ผ่านมา

      Yes that would work too.

  • @BizInsightHub1
    @BizInsightHub1 4 วันที่ผ่านมา

    Can you explain about the seg tree why minimum?

  • @Dota2Vibes
    @Dota2Vibes 4 วันที่ผ่านมา

    Love your videos man. Thanks for all your hard work. You should definitely post these in leetcode solutions section

  • @Yadavprash9
    @Yadavprash9 4 วันที่ผ่านมา

    Thanks, really appreciate the video, though I am just starting to learn these concepts, the thought process was good to know, going to checkout the playlists in the description :)

  • @yourmomforsenhead914
    @yourmomforsenhead914 5 วันที่ผ่านมา

    dont pajeets poop on the street?

  • @sonugupta147
    @sonugupta147 5 วันที่ผ่านมา

    Your explanation is really impressive. The ideas and observations you put at every step.. its just the evidence of how a problem should be approached.

  • @NAMANSINGH-d2z
    @NAMANSINGH-d2z 5 วันที่ผ่านมา

    trie dp keeps giving me mle,can you tell what further optimistion is needed in my case struct Node{ Node *links[26]; bool end = false; bool containsKey(char ch) { return links[ch - 'a'] != NULL; } void put(char ch,Node* node) { links[ch - 'a'] = node; } Node* get(char ch) { return links[ch - 'a']; } bool isEnd() { return end; } void setEnd() { end = true; } }; class Trie { Node* root; public: Trie() { root = new Node(); } void insert(string word) { Node* node = root; for(int i = 0; i<word.size(); i++) { if(!node->containsKey(word[i])) { node->put(word[i],new Node()); } node = node->get(word[i]); } node->setEnd(); } bool prefix(string prefix) { Node* node = root; for(int i = 0; i<prefix.size(); i++) { if(!node->containsKey(prefix[i])) { return false; } node = node->get(prefix[i]); } return true; } }; class Solution { public: int n,m; // int dp[5005]; Trie* trie = new Trie(); int solve(vector<string>& words, string& target,int idx,vector<int>& dp) { if(idx >= n) return 0; if(dp[idx]!=-1) return dp[idx]; int res = 1e9; for(int i = idx; i<n; i++) { string temp = target.substr(idx,i-idx+1); if(trie->prefix(temp)) res = min(res,1+solve(words,target,i+1,dp)); } return dp[idx] = res; } int minValidStrings(vector<string>& words, string target) { m = words.size(); n = target.size(); for(int i = 0; i<m; i++) trie->insert(words[i]); // memset(dp,-1,sizeof dp); vector<int> dp(n+1,-1); int res = solve(words,target,0,dp); return res == 1e9 ? -1 : res; } };

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      You are finding out the "temp" and then iterating over it again (using trie) to get the answer. Hence inside the outer for loop (of idx), you have a hidden for loop which will also run for upto a size of T. Therefore making complexity of single state as T×T in worst case. You can optimize the hidden loop by reusing the iterations done in previous steps. For example, notice that the new "temp" is simply having 1 more character than the previous one. Hence you can persist the trie node you reached in previous iteration and simply continue 1 more step from there. Something like - temp_root = trie->root for I in (idx, n): temp_root = temp_root->get(targeti) ....

    • @NAMANSINGH-d2z
      @NAMANSINGH-d2z 5 วันที่ผ่านมา

      ​@@codingmohan thanks for this, i was not able to think about the hidden loop. The idea of using previous node is great, i am sure it will help in future also, thanks

    • @sanjanadutta7145
      @sanjanadutta7145 4 วันที่ผ่านมา

      @@NAMANSINGH-d2z can you share your accepted code?

  • @satyamraj2779
    @satyamraj2779 5 วันที่ผ่านมา

    thanks for making credible editorials.

  • @nikhilprakash729
    @nikhilprakash729 5 วันที่ผ่านมา

    Great Solution...

  • @hmlks4836
    @hmlks4836 5 วันที่ผ่านมา

    getting tle with the approach of 3 problem using recursion + memo+trie, please look into my solution

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Hope this is resolved now?

  • @hmlks4836
    @hmlks4836 5 วันที่ผ่านมา

    class Solution { HashMap<String, Boolean> map=new HashMap(); class TrieNode { TrieNode[] children; boolean isEndOfWord; public TrieNode() { children = new TrieNode[26]; isEndOfWord = false; } } public void insert(String word, TrieNode root) { TrieNode node = root; for (char c : word.toCharArray()) { int index = c - 'a'; if (node.children[index] == null) { node.children[index] = new TrieNode(); } node = node.children[index]; } node.isEndOfWord = true; } public boolean findWordsWithPrefix(String prefix, TrieNode root) { TrieNode node = root; int result=0; for (char c : prefix.toCharArray()) { int index = c - 'a'; if (node.children[index] == null) { return false; // No match for the prefix } else result++; node = node.children[index]; } return true; } public int find(String s, TrieNode root, HashMap<Integer , Integer> memo, int index, int n){ // System.out.println(s); // int n1=s.length(); if(index==n) return 0; if(memo.containsKey(index)) return memo.get(index); boolean found=false; int x=10000000; String temp=""; for(int i=index;i<s.length();i++){ temp+=s.charAt(i); boolean cnt=false; if(map.containsKey(temp)) cnt=map.get(temp); else { cnt=findWordsWithPrefix(temp, root); map.put(temp, cnt); } if(cnt) { // System.out.println(s+" temp: "+temp+" "+" child: "); int child=find(s, root, memo, i+1, n); if(child!=-1){ x=Math.min(x,child ); found=true; } } else break; } if(!found){ memo.put(index,-1); return -1; } memo.put(index,x+1); return x+1; } public int minValidStrings(String[] words, String target) { int n=words.length; TrieNode root=new TrieNode(); for(int i=0;i<n;i++){ insert(words[i], root); } HashMap<Integer, Integer> memo=new HashMap<>(); return find(target, root, memo, 0, target.length()); } }

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      if(map.containsKey(temp)) cnt=map.get(temp); else { cnt=findWordsWithPrefix(temp, root); map.put(temp, cnt); } Why are you creating a temporary string and the searching it in a hashmap. Why not simply iterate over the trie and let trie do the work? Something like - tmp_root = root for(int i=index;i<s.length();i++){ tmp_root = tmp_root.children [s[i] - 'a'] if (tmp_root == null) break; // The node exist, which in turn means that there is a valid string (prefix of some word in 'words') ans = min(ans, 1 + find(s, root, memo, i+1, n)); } The thing is, with your approach, you are searching for the word all over again by starting your search from "root" everytime and hence for every index, you'll be iterating over all previous indexes and hence the complexity would be T*T instead of T. Feel free to follow-up if something is unclear.

    • @ujjwalagnihotri5001
      @ujjwalagnihotri5001 5 วันที่ผ่านมา

      Java's HashMap is too slow, apart from above optimization use array for dp and trie.

    • @hmlks4836
      @hmlks4836 5 วันที่ผ่านมา

      @@codingmohan thanks, i got u.

  • @hmlks4836
    @hmlks4836 5 วันที่ผ่านมา

    Still getting TLE. 916/929 :((((

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Replied to the other comment. Let me know if you are still facing issues.

  • @guruharsha6275
    @guruharsha6275 5 วันที่ผ่านมา

    Can u post solutions yesterday's biweekly contests hard questions?

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Here you go - th-cam.com/video/ea9Kjfc9ZzI/w-d-xo.html

    • @guruharsha6275
      @guruharsha6275 5 วันที่ผ่านมา

      @@codingmohanand the 4th one?

  • @Cools74
    @Cools74 5 วันที่ผ่านมา

    Please try to upload yesterday biweekly contest 3rd problem 🙏

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Here you go - th-cam.com/video/ea9Kjfc9ZzI/w-d-xo.html

    • @Cools74
      @Cools74 5 วันที่ผ่านมา

      @@codingmohan Thanks a lot 😭

  • @nikhilsoni2403
    @nikhilsoni2403 5 วันที่ผ่านมา

    Great explaination ❤. The z function approach is really understandable .

  • @mridul1075
    @mridul1075 5 วันที่ผ่านมา

    class Solution { public: vector<vector<int>> memo; int rec(int i, int mask, vector<vector<int>>& grid) { if (i == grid.size()) return 0; if (memo[i][mask] != -1) return memo[i][mask]; int mxscore = rec(i + 1, mask, grid); for (int j = 0; j < grid[0].size(); j++) { if ((mask & (1 << grid[i][j])) == 0) { mask = mask | (1 << grid[i][j]); mxscore = max(mxscore, grid[i][j] + rec(i + 1, mask, grid)); mask = mask ^ (1 << grid[i][j]); } } return memo[i][mask] = mxscore; } int maxScore(vector<vector<int>>& grid) { int m = grid.size(); memo.assign(m, vector<int>(1 << 10, -1)); return rec(0, 0, grid); } }; can anyone please help me why this solution is not working

  • @tanishgotti3659
    @tanishgotti3659 6 วันที่ผ่านมา

    Thank you for the clear explanation.

  • @rohanthakur9159
    @rohanthakur9159 6 วันที่ผ่านมา

    Thanks for the awesome tutorials. And thanks for 2 solutions here

  • @talwaarkidhaar
    @talwaarkidhaar 7 วันที่ผ่านมา

    Wish you explained the Combinations solution as well

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      You can try it yourself and I can help correct you as needed :)

  • @coding6763
    @coding6763 7 วันที่ผ่านมา

    Hi please change videos in playlists from newest to oldest . Its a request

  • @PawanSingh-i5e5g
    @PawanSingh-i5e5g 8 วันที่ผ่านมา

    Khuch bhi samjh nhi aya mirror image bhi nhi 😭

  • @youcanyouwill2004
    @youcanyouwill2004 8 วันที่ผ่านมา

    amazing explaination. Thank You ❤❤❤

  • @SahilKumar-sj6il
    @SahilKumar-sj6il 11 วันที่ผ่านมา

    This channel is such a hidden gem that if anyone just randomly follow any playlist of him will be master of it . Just do it you will be +500 rated everywhere if you are pupil,specialist even expert

  • @laxman1225
    @laxman1225 11 วันที่ผ่านมา

    Last taken is position of 22:22 knight❤

  • @mohdhammadsiddiqui7598
    @mohdhammadsiddiqui7598 12 วันที่ผ่านมา

    Sir whats wrong with my approach struggling since morning class Solution { public: vector<int> dx = {-2, -2, -1, -1, 1, 1, 2, 2}; vector<int> dy = {-1, 1, -2, 2, -2, 2, -1, 1}; int helper(int kx, int ky, pair<int, int> pyaada, vector<vector<int>>& visited, vector<vector<int>>& dp) { if (kx == pyaada.first && ky == pyaada.second) { return 0; } if (kx < 0 || kx >= 50 || ky < 0 || ky >= 50) return 1e9; if (dp[kx][ky] != -1) return dp[kx][ky]; int mini = 1e9; if (visited[kx][ky] == 1) return 1e9; visited[kx][ky] = 1; for (int i = 0; i < 8; i++) { int answer = 1 + helper(kx + dx[i], ky + dy[i], pyaada, visited, dp); mini = min(mini, answer); } visited[kx][ky] = 0; return dp[kx][ky] = mini; } int getMinMoves(int kx,int ky ,pair<int,int> pyaada) { vector<vector<int>> visited(50,vector<int>(50,-1)); vector<vector<int>> dp(50,vector<int>(50,-1)); return helper(kx,ky,pyaada,visited,dp); } int maxMoves(int kx, int ky, vector<vector<int>>& positions) { bool aliceTurn = true; int score = 0; set<pair<int,int>> pyaadePositions; for(auto itr :positions) { pyaadePositions.insert({itr[0],itr[1]}); } while(pyaadePositions.size() >0 ) { int currentMinMoves =1e9; int currentMaxMoves =0; pair<int,int> minPyaada,maxPyaada; for(auto position:pyaadePositions) { int val = getMinMoves(kx,ky,position); if(val >currentMaxMoves) { currentMaxMoves = val; maxPyaada = position; } if(val<currentMinMoves) { currentMinMoves = val; minPyaada = position; } } if(aliceTurn) { score += currentMaxMoves; kx = maxPyaada.first; ky = maxPyaada.second; pyaadePositions.erase(maxPyaada); } else { score+= currentMinMoves; kx = minPyaada.first; ky = minPyaada.second; pyaadePositions.erase(minPyaada); } aliceTurn = !aliceTurn; } return score; } };

  • @mayanksharma2039
    @mayanksharma2039 12 วันที่ผ่านมา

    For finding the minimum distance you can use indexes of the pawns array in a 2D matrix of size N*N, where distance[i][j] represents shortest distance to reach from pawn at index i to pawn at index j(where N is the size of pawns array,) and for every index you calculate the shortest distance to every other cell which can be done in 50*50 for a single Pawn and for N pawns it boils down to 50*50*N (here N <= 15). And to check whether or not a given (x,y) represents a pawn we can use a hash map where each pawn is mapped to its index in pawns array

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Good point. I didn't notice this because all pair version passed.

  • @bishwashkumarsah171
    @bishwashkumarsah171 12 วันที่ผ่านมา

    please do video for q.2 and q.3 also

  • @adityaroychowdhury3709
    @adityaroychowdhury3709 12 วันที่ผ่านมา

    I was very close, coded out bitmask dp all the way. Got WA tho :( Thankyou for this

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Happens. The best thing is that you tried to upsolve and hopefully will get 1 step closer next time :)

  • @AlishaGupta-u1k
    @AlishaGupta-u1k 13 วันที่ผ่านมา

    Best explanation i could find ! thankyou. Keep up the good work..

  • @rajchinagundi7498
    @rajchinagundi7498 14 วันที่ผ่านมา

    first half of the video was okay, next half felt like you were trying to convince yourself. Please take it as a constructive criticism, it really means a lot for people like us who are tying to upsolve. Your videos are indeed helpful.

    • @codingmohan
      @codingmohan 5 วันที่ผ่านมา

      Thank you for feedback. Maybe it's because I record the video in 1 go. Will try to improve.

  • @dsadecode
    @dsadecode 14 วันที่ผ่านมา

    Great Explanation Sir

  • @blessmewithlight
    @blessmewithlight 14 วันที่ผ่านมา

    very nice solution sir thanku so much

  • @360Anurag
    @360Anurag 15 วันที่ผ่านมา

    Its pronounced as Ex-OR

  • @Luffycoding-b1y
    @Luffycoding-b1y 15 วันที่ผ่านมา

    i am unable to find where my code is wrong can u please fix my code Output [10,10,10] Expected [6,10,7] *** from typing import List from bisect import bisect_left class segment: def __init__(self,arr): self.n = len(arr) self.seg = [None]*(4*self.n) self.build(0,0,self.n-1,arr) def build(self,i,l,r,v): if l == r: self.seg[i] = [[v[l][1],v[l][0]+v[l][1]]] return mid = (l+r)//2 self.build(2*i+1,l,mid,v) self.build(2*i+2,mid+1,r,v) self.seg[i] = self.merge(self.seg[2*i+1],self.seg[2*i+2]) def merge(self,s1,s2): l = len(s1) l1 = len(s2) c = [None]*(l+l1) i,j,k = 0,0,0 while i < l and j < l1: if s1[i] < s2[j]: c[k] = s1[i] i += 1 k += 1 else: c[k] = s2[j] j += 1 k += 1 while i < l: c[k] = s1[i] k+= 1 i+= 1 while j < l1: c[k] = s2[j] j += 1 k += 1 for i in range(len(c)-2,-1,-1): c[i][1] = max(c[i][1],c[i+1][1]) return c def query(self,l,r,low,high,y,i): if low > r or high < l: return -1 if low >= l and high <= r: arr = self.seg[i] ind = bisect.bisect_left(arr,[y,-1]) print(ind) if ind == len(arr): return -1 return arr[ind][1] mid = (low+ high)//2 left = self.query(l,r,low,mid,y,2*i+1) right = self.query(l,r,mid+1,high,y,2*i+2) return max(left,right) class Solution: def maximumSumQueries(self, A: List[int], B: List[int], Q: List[List[int]]) -> List[int]: n = len(A) m = len(Q) ans = [] v = list(zip(A, B)) v.sort() mt = segment(v) for x, y in Q: l = bisect_left(v, (x, -1)) print(l) print(mt.seg) print(l,n-1) res = mt.query(l,n-1,0,n-1,y,0) ans.append(res) return ans ***

  • @abhishekrai3
    @abhishekrai3 15 วันที่ผ่านมา

    Thanks alot for the amazing editorial, mai apke channel ko bahot pehle se follow kar rha hu, and apke editorial ki ek sabse khash baat hai ki, ki aakhir sochana kaise hai, solution tak kaise pahoche ye sikhane ko milta ho, Thanks alot for the amazing editorials.

  • @selvaragavan_10
    @selvaragavan_10 15 วันที่ผ่านมา

    Bro great please change the color of your cursor. It is not visible when seen from mobile.

  • @sanchitkumar6626
    @sanchitkumar6626 15 วันที่ผ่านมา

    happy teachers day bhaiya. Thank you for giving such quality vidios for free. we will always be grateful to you.