Bifalgorithm post
"learn pattern recognition i'll give you one input array and i'll ask you four different questions and you have to tell me what pattern to apply question is very simple you will be given an array and you have to say is there any two elements present whose sum is equal to target means you have to give me any two such elements suppose target is seven so you have to check two and five yes there are two elements present whose sum is equal to target Is it similar to two sum problem? Yes. Second, question says any subarray whose sum is equal to target. Means you know, subarray is the continuous array. And suppose the question is, is there any subarray whose sum is equal to 11? And you will find, yes, it is. So this concept is not two-pointer. Why? Because from a particular point to particular point, you collected every element which come into this. Even you start with two-pointers only, like a left-pointer and right-pointer, but you keep on including every such point comes in between. And that is not two-pointer. That is called sliding window approach. So out of all... such subarrays you have to say ki which subarrays has the maximum sum so in that case definitely the larger subarray and hence the question becomes so easy here definitely they will mention a k value means the subarray size they will fix and now they will ask tell me the maximum subarray And remember in this case they will not give you the sorted array. But here also it's a trick. If all numbers are positive then only you can apply sliding window. And if any negative number exists then definitely sliding window fails. And you have to apply Kadde in Selgortam there. Last is count all such subarrays whose sum is equal to target. Means you have to find all numbers of subarrays whose sum is equal to target. Suppose you want 11 right? 2 plus 4 plus 5 will also give you 11 subarray sum. And 5 plus 6 will also give you 11 subarray sum. So here how many such subarrays? were there too and remember whenever you have to count sub-arrays prefix sum plus hash map comes all patterns i discussed that is only used for optimizing your code and not in the brute force and hence for optimize you have to learn the pattern then only you can recognize on their own so stop blaming yourself and start learning patterns which we are doing on our youtube channel comment link to get the link in your dms"
"learn pattern recognition i'll give you one input array and i'll ask you four different questions and you have to tell me what pattern to apply question is ve…
Ideas in this flowchart
- Pattern Recognition in Arrays
- Two Sum Problem
- Find two elements whose sum equals target
- Subarray Sum Problem
- Find subarray whose sum equals target
- Sliding Window Approach
- Not applicable with negative numbers
- Kadane's Algorithm
- Maximum Subarray Problem
- Find maximum subarray of fixed size k
- Subarray Count Problem
- Count all subarrays whose sum equals target
- Use prefix sum and hashmap for optimization
- Learning Patterns
- Stop blaming and start learning
- YouTube channel for pattern learning