Notes/Codes/Problem links under step 10 of A2Z DSA Course: takeuforward.org/strivers-a2z... Entire playlist: • Two Pointer and Slidin... Follow us on our other social media handles: linktr.ee/takeuforward
Understood Striver. Was able to reuse the same code that was implemented in previous lecture before starting to watch the solution. Thank you again for such a great explanation
@@txbankush4601 for previous problem int totalFruits(int N, vector &arr) { int left = 0, right = 0, maxLength = 0; unordered_map map; while (right < N) { map[arr[right]]++; if (map.size() > 2) { map[arr[left]]--; if (map[arr[left]] == 0) { map.erase(arr[left]); } left++; } if(map.size()
I used to struggle a lot with sliding window Questions Thanks to u and your playlist because of which i am able to solve this type of Questions. Thankyou very much.
Could we use use queue to store char and the index of that character? The latest one and when size increases to 3 then we drop the front and take the latest index. Update the length and r keep on going. I just don't want that while loop running to find our l.
Why was it O(256) space for brute force? because size is k distinct right? like as soon as size becomes k+1, we break. i didn't understand why so much extra space is being taken
suppose the len of string is 256 containing all different characters and k = 256 then space will be O(256) he is writing everything in worst case thats like upper bound
@@30sunique78 Hashmap works in logarithmic time , while vector/array/list in constant time Although if you are working in c++ there is also unordered map which works in constant time but still even then it is prefered to work with vectors as the constants involved with vector are better than hash maps
Hey, I didn't understand one thing, that he mentions extra TC O(log 256) where is this coming from? plus he is saying Space complexity as O(256) but there are only 26 alphabets right, then how is it 256 instead of 26? can someone plzz clarify this with detailed explanation or some video link/ references to understand this! Thank you
n^2 happens only when for every constant j -> i runs till end, but here overall i runs only once and j also runs only once throughout the program. watch previous lecture striver has explained it
what happens when string is "AABABBA" Actual output will be 5 but current code will give 7, here k=2 means at max 2 times A to B conversion or vice versa can be done as per leetcode
Inputs & expected output from leetcode 1) Input: s = "ABAB", k = 2 Output: 4 Explanation: Replace the two 'A's with two 'B's or vice versa. 2) Input: s = "AABABBA", k = 1 Output: 4 Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA". The substring "BBBB" has the longest repeating letters, which is 4. There may exists other ways to achieve this answer too.
import java.util.HashMap; public class Solution { public static int kDistinctChars(int k, String str) { int l=0; int r=0; int maxlen=0; HashMapmpp=new HashMap(); while(r
Question in sheet is not correctly mapped with the video It expects to interchange any k char and by doing so find the longest string with same character and in the video it is changing all occurances of a distinct characters and for all instance of k different character.