Hey, I am a Software Engineer. Where? You can find that on my LinkedIn. Also, I am a Candidate Master(2020) at Codeforces and a 6*(2019) at Codechef. In this channel, I try to create content which can help some of you.
I teach DSA stuff, I try to make it as easy as possible. The best thing about this channel is, you will find the thought process behind every problem and not just simple algorithms. All of the content is in English so that anyone can watch it. I also take live sessions on a channel named CodeBeyond, and I keep posting roadmaps on my second channel "Striver"
Codeforces/Codechef: striver_79
Subscribe to the channel and press the bell 🔔 for the latest updates!
public static int maxScore(int[] cardPoints, int k) { int lsum =0, rsum =0, max =0,sum =0; int n = cardPoints.length; for(int i=0;i<k;i++){ lsum = lsum + cardPoints[i]; } max = lsum; for (int i = 0; i < k; i++) { lsum -= cardPoints[k-1-i]; rsum += cardPoints[cardPoints.length -1-i]; sum = lsum+rsum; if(sum>max){ max = sum; } } return max; } same approach but easier to understand
The palindrome problem can also run without including<iostream> using namespace std; as --- bool palindrome(int n) { int reversenum = 0; int dup = n; while (n > 0) { int ld = n % 10; reversenum = (reversenum * 10) + ld; n = n / 10; } return dup == reversenum; if (dup == reversenum) cout << "true" << endl; else cout << "false" << endl; }
I have a small doubt, during 3rd recursive call the list is [3,2,1] and i value is 3. Now as i= arr.length, we print the list. After that to back track, we remove recently added element which is 2. Now the list becomes [3,1] but the i value doesnt change. It remains same 3.and after removing, we did sub(al,arr,i+1) which is sub([3,1],arr,4).im confusing here
So in prev video, a method was taught to find ~x but it is a bit unclear. Let me try clear it up. Actually, ~x is just 1's complement of x, i.e., flip all bits. Eg: ~19 = ~(010011) = (101100) in binary = -20 in decimal Now we know (-x) is actually 2's complement of x. So what he taught is actually to find -x manually. Take prev eg, ~(010011) = (101100) in binary = -(2's complement of 101100) in decimal = -(010100) in decimal = -20 Take other way, ~(-20) = ~(101100)=010011 in binary=(directly) 19 Note: For easiness just assume that instead of 32 bits, there are only 6 bits here.
one thing I didn't understand is that subsets do not contain duplicates, but in the dry run there may be a case where 2 same elements can be subtracted from the target making the target zero, but this should not be counted as a subset...
class Solution { public: int fun(vector<int>& arr, int goal){ if(goal < 0 ) return 0; int l = 0, r = 0 , cnt = 0; int sum = 0; while(r < arr.size()){ sum += arr[r]; while(sum > goal){ sum -= arr[l]; l++; } cnt += r - l + 1; r++; } return cnt; } int numSubarraysWithSum(vector<int>& nums, int goal) { return fun(nums,goal) - fun(nums,goal - 1); } };