Aditya Verma
Aditya Verma
  • 148
  • 24 063 875
13 Rat in a Maze Problem Code
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matrix represents that it is blocked and rat cannot move to it while value 1 at a cell in the matrix represents that rat can be travel through it.
Note: In a path, no cell can be visited more than one time. If the source cell is 0, the rat cannot move to any other cell.
Example 1:
Input:
N = 4
m[][] = {{1, 0, 0, 0},
{1, 1, 0, 1},
{1, 1, 0, 0},
{0, 1, 1, 1}}
Output:
DDRDRR DRDDRR
Explanation:
The rat can reach the destination at
(3, 3) from (0, 0) by two paths - DRDDRR
and DDRDRR, when printed in sorted order
we get DDRDRR DRDDRR
Problem Statement link: www.geeksforgeeks.org/problems/rat-in-a-maze-problem/1
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3TyU2IU
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.
Переглядів: 11 736

Відео

12 Rat in a Maze Problem
Переглядів 7 тис.4 місяці тому
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matrix represents that it is blocked and rat cannot move to it while value 1 at a...
11 N Digit numbers with digits in increasing order
Переглядів 5 тис.4 місяці тому
Given an integer N, print all the N digit numbers in increasing order, such that their digits are in strictly increasing order(from left to right). Example 1: Input: N = 1 Output: 0 1 2 3 4 5 6 7 8 9 Explanation: Single digit numbers are considered to be strictly increasing order. Here are some of the gears that I use almost everyday: 🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1 👨🏻‍💻 : My ...
10 Largest number in K swaps Code and Time Complexity
Переглядів 6 тис.4 місяці тому
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times. Example 1: Input: K = 4 str = "1234567" Output: 7654321 Explanation: Three swaps can make the input 1234567 to 7654321, swapping 1 with 7, 2 with 6 and finally 3 with 5 Here are some of the gears that I use almost everyday: ...
9 Largest number in K swaps
Переглядів 12 тис.6 місяців тому
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times. Example 1: Input: K = 4 str = "1234567" Output: 7654321 Explanation: Three swaps can make the input 1234567 to 7654321, swapping 1 with 7, 2 with 6 and finally 3 with 5 Here are some of the gears that I use almost everyday: ...
8 Permutation of Strings | Backtracking Solution
Переглядів 12 тис.6 місяців тому
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order. Example 1: Input: ABC Output: ABC ACB BAC BCA CAB CBA Explanation: Given string ABC has permutations in 6 forms as ABC, ACB, BAC, BCA, CAB and CBA . Example 2: Input: ABSG Output: ABGS ABSG AGBS AGSB ASBG ASGB BAGS BASG BGAS BGSA BSAG BSGA GABS GASB GBAS GBSA GSAB GSBA SABG SAGB...
7 Time Complexity of a Recursive Tree
Переглядів 9 тис.6 місяців тому
Time complexity of a recursive solution can easily be derived by its recursive tree, it's simply the number of nodes times the complexity of one node. Here are some of the gears that I use almost everyday: 🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1 👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6 💻 : My gaming laptop: amzn.to/3yjcn23 📱 : My Ipad: amzn.to/39yEMGS ✏️ : My Apple Pencil: amzn.to...
6 Permutation of Strings | Simple Recursion
Переглядів 18 тис.7 місяців тому
Given a string S. The task is to print all unique permutations of the given string in lexicographically sorted order. Example 1: Input: ABC Output: ABC ACB BAC BCA CAB CBA Explanation: Given string ABC has permutations in 6 forms as ABC, ACB, BAC, BCA, CAB and CBA . Example 2: Input: ABSG Output: ABGS ABSG AGBS AGSB ASBG ASGB BAGS BASG BGAS BGSA BSAG BSGA GABS GASB GBAS GBSA GSAB GSBA SABG SAGB...
5 Backtracking Problems
Переглядів 11 тис.7 місяців тому
In this video, we will learn about the possible problems that we will cover under backtracking. I think after solving and understanding these 10 problems, you should be able to approach any other backtracking problem.
4 Generalization of Backtracking
Переглядів 15 тис.7 місяців тому
In this video, we will learn about the template that any backtracking solution fits into, and we will try to write a generalized pseudo code for any backtracking problem.
3 Identification of Backtracking Problems
Переглядів 15 тис.7 місяців тому
In this video, we will learn how to identify backtracking problems and understand different properties that, when noticed, should definitely lead you to consider applying backtracking. Music I use: www.bensound.com License code: Q1IAPI4RNZSUDBQA
2 Basics of Backtracking
Переглядів 37 тис.7 місяців тому
In this video, we will learn about the basics of backtracking and how it is different from other recursion variants. Music I use: www.bensound.com License code: Q1IAPI4RNZSUDBQA
1 Backtracking Course Overview
Переглядів 54 тис.7 місяців тому
In this video, we will familiarize ourselves with what the playlist is going to hold for us. Thanks to @airajena5036 for chapters: 0:00 - Course Overview 0:30 - What's actual Backtracking? 0:45 - Recursion vs Backtracking 1:15 - Pass by value vs Pass by Reference 1:30 - Identification 1:45 - Generalization 1:50 - Data Structures vs Algorithms 3:40 - Problems Music I use: www.bensound.com Licens...
Is Aditya Verma dead? Channel hijacked?
Переглядів 47 тис.7 місяців тому
Backtracking series starts tomorrow
Minimum Window Substring | Variable Size Sliding Window
Переглядів 193 тис.3 роки тому
Check out the batches here: unacademy.com/goal/competitive-programming/LEARNCP/batches Check out all the free classes in the current week here: unacademy.cc/daily_learning Check out the Star Educators here: unacademy.cc/EducatorYT Prodigy 2021: Comprehensive Course to Become a Codechef certified Expert Programmer (C ): bit.ly/prodigyc Prodigy 2021: Comprehensive Course to Become a Codechef cert...
Pick Toys | An Interesting Sliding Window Problem
Переглядів 86 тис.3 роки тому
Pick Toys | An Interesting Sliding Window Problem
Longest Substring With Without Repeating Characters | Variable Size Sliding Window
Переглядів 134 тис.3 роки тому
Longest Substring With Without Repeating Characters | Variable Size Sliding Window
Longest Substring With K Unique Characters | Variable Size Sliding Window
Переглядів 151 тис.3 роки тому
Longest Substring With K Unique Characters | Variable Size Sliding Window
Variable Size Sliding Window General Format
Переглядів 107 тис.3 роки тому
Variable Size Sliding Window General Format
Largest Subarray of sum K | Part2
Переглядів 151 тис.3 роки тому
Largest Subarray of sum K | Part2
Variable Size Sliding Window | Largest Subarray of sum K | Part1
Переглядів 144 тис.3 роки тому
Variable Size Sliding Window | Largest Subarray of sum K | Part1
Maximum of all subarrays of size k | Sliding Window
Переглядів 211 тис.3 роки тому
Maximum of all subarrays of size k | Sliding Window
Count Occurrences Of Anagrams | Sliding Window
Переглядів 213 тис.3 роки тому
Count Occurrences Of Anagrams | Sliding Window
How To Debug Your Code | How To Solve Any Coding Problem In Your Interview Part 3
Переглядів 34 тис.3 роки тому
How To Debug Your Code | How To Solve Any Coding Problem In Your Interview Part 3
Significance Of The Constraints | How To Solve Any Coding Problem In Your Interview Part 2
Переглядів 41 тис.3 роки тому
Significance Of The Constraints | How To Solve Any Coding Problem In Your Interview Part 2
Giveaway of 2000 INR To The Community | Aditya Verma
Переглядів 7 тис.3 роки тому
Giveaway of 2000 INR To The Community | Aditya Verma
How To Solve Any Coding Problem In Your Interview Part 1 | Time Management | Experience And Mistakes
Переглядів 101 тис.3 роки тому
How To Solve Any Coding Problem In Your Interview Part 1 | Time Management | Experience And Mistakes
First Negative Number in every Window of Size K | Sliding Window
Переглядів 242 тис.3 роки тому
First Negative Number in every Window of Size K | Sliding Window
Maximum Sum Subarray of size K | Sliding Window
Переглядів 302 тис.3 роки тому
Maximum Sum Subarray of size K | Sliding Window
Sliding Window Problems
Переглядів 198 тис.3 роки тому
Sliding Window Problems

КОМЕНТАРІ

  • @buntyagarwal7717
    @buntyagarwal7717 19 годин тому

    Scs is not their its hidden

  • @shubhampathak260
    @shubhampathak260 19 годин тому

    Plz kisi ko mat btaya karo is playlist ke bare me competition bhut bad jayega...... 😂😂😂😂

  • @sonaprajapat8207
    @sonaprajapat8207 20 годин тому

    Whenever I need prepare Interview I just come here... And now I am seeing you r back... Great

  • @shubhampathak260
    @shubhampathak260 21 годину тому

    me to coachings of DSA - DP bhut tough topic h achhe se padha doge..?? They replied- ha ha sabse achha lekin aditya karke koi h usse achha ni padha payenge to be honest 😂😂😂😂 pta pada bad me fee refund mangne lago...

  • @Mohit_Gupta24
    @Mohit_Gupta24 23 години тому

    Hello, this approach will not work if we include negative numbers in the array, right ?

  • @Mohit_Gupta24
    @Mohit_Gupta24 23 години тому

    I find the Tabular approach less intuitive, and prefer Brute Force Recursive approach. As s2 = (Range - 2*s1) and s1 lies between 0 < s1< range/2. So in order to have a min Range - 2*s1, we need to maximize s1, so can we start searching possible sum in subset of the input array from range sum to 0 in decreasing order, and once we find the first sum is possible to make, that will be our answer? Thoughts?

  • @Yash-afk
    @Yash-afk День тому

    Nice explanation bhaiya, here is how i did it in Java: import java.util.*; class connectRopes{ public static void main(String[] args) { int[] arr={1,2,3,4,5}; PriorityQueue<Integer> min_heap= new PriorityQueue<>(); for (int val : arr) { min_heap.add(val); } System.out.println(min_heap); int cost=0; while(min_heap.size()>=2){ int f=min_heap.poll(); int s=min_heap.poll(); // System.out.println("//f+s "+(f+s)); cost+=(f+s); // System.out.println("//cost "+cost+" "); min_heap.add(f+s); } System.out.println(cost); } }

  • @amansingh.h716
    @amansingh.h716 День тому

    AMAZING

  • @suhelalam2686
    @suhelalam2686 День тому

    I am still confuse on why at last we are returning Temp.

  • @danushbasanaboyina1306
    @danushbasanaboyina1306 2 дні тому

    The best explanation in the youtube on DP where I found the explanation even in Matrix wise ,where no one does..

  • @ayushisarkar682
    @ayushisarkar682 2 дні тому

    Pls explain me if mid ==k then why we can't return mid +1 element as array is sorted so next element would be in mid +1 Can someone please explain

  • @tirthshah2832
    @tirthshah2832 2 дні тому

    C++ code: class Solution { public: void solve(string &str, int k, int start, string &ans){ if(k==0 || start==str.size()-1){ return; } char maxs= *max_element(str.begin()+start,str.end()); for(int i=start+1;i<str.size();i++){ if(str[start]<str[i] && str[i]==maxs){ swap(str[start], str[i]); if(str.compare(ans)>0) ans=str; solve(str,k-1,start+1,ans); swap(str[start], str[i]); } } solve(str,k,start+1,ans); } //Function to find the largest number after k swaps. string findMaximumNum(string str, int k) { // code here string ans=str; solve(str,k,0,ans); return ans; } };

  • @rhishishrivastava675
    @rhishishrivastava675 2 дні тому

    a simpler way to understand this problem is as follows: let the sum of the array is S. two subsets having sum S1 and S2. Therefore S1 + S2 = S; we have to minimize the difference of the two subsets sum S1 and S2. we have to minimize S1 - S2 , minimum diff will begin at 0 and then 1, then n go up to S as one full set and one empty set diff. now we know S1 + S2 = S S1 - S2 will be one of 0,1,2,...,S so let's begin with checking 0, that means S1 - S2 = 0; problem becomes equal subset problem. if not that, then we will check 1, while checking1 equations will be S1 + S2 = S S1 - S2 = 1 which results 2S1 = S + 1 S1 = (S+1)/2 while checking 0 as minimum, it as S1 = (S + 0 ) / 2 general eq will be ( S + i )/2. so we have check in loop if there lies a subset in array whose sum is ( S + i )/2. Inside loop call the helper function to check if subset occurs. which can be done as follows. This solution works for arrays with negative elements too. int minimumDifference(vector<int>& nums) { int sum = 0, ans = 0; for(auto & a : nums) sum += std::abs(a);//sum with abs elements int s = std::accumulate(nums.begin(),nums.end(),0);//sum with negative numbers for(int i = 0; i < sum +1; i++) { int res = helper(nums,nums.size(),(s+i)/2,vec); if(res == 1) { ans = i; break; } } return ans; } int helper(vector<int>& nums, int n, int sum, std::vector<std::vector<bool>>& vec) { if(sum == 0 && n == nums.size()) return 0; if(sum == 0) return 1; if(n==0) return 0; if(nums[n-1]<= sum) { return helper(nums, n-1, sum - nums[n-1], vec) || helper(nums, n-1, sum, vec); } else { return helper(nums, n-1, sum, vec); } } please like the comment if it helps, this will help me knowing if I am able to help someone. this playlist has been quite helpful for me so far. Learning DP after leaving college 11 years back.

  • @aayush4056
    @aayush4056 2 дні тому

    Khud kr lia vro

  • @akritipandey1387
    @akritipandey1387 2 дні тому

    this code is optimized and is same as u have told in the video still it is not passing all the test cases showing TLE Can someone help me with this pls //{ Driver Code Starts // Initial Template for c++ #include <bits/stdc++.h> using namespace std; // } Driver Code Ends // User function Template for C++ class Solution{ public: //RECURSIVE TLE bool ispalindrome(string str,int i,int j) { while(i<j) { if(i>=j) return true; if(str[i]!=str[j]) { return false; } i++; j--; } return true; } int solve(string str,int i,int j,vector<vector<int>> &dp) { if(i>=j) { return 0; } //check if already palindrome //no partition required if(ispalindrome(str,i,j)) return 0; if(dp[i][j]!=-1) return dp[i][j]; int ans=INT_MAX; int left=0; int right=0; for(int k=i;k<=j-1;k++) { if(dp[i][k]!=-1) { left=dp[i][k]; } else { left=solve(str,i,k,dp); dp[i][k]=left; } if(dp[k+1][j]!=-1) { right=dp[k+1][j]; } else { right=solve(str,k+1,j,dp); dp[k+1][j]=right; } int temp=1+left+right; if(temp<ans) ans=temp; } return dp[i][j]=ans; } int palindromicPartition(string str) { int n=str.length(); int p=0; int q=n-1; vector<vector<int>>dp(n,vector<int>(n,-1)); return solve(str,p,q,dp); } //{ Driver Code Starts. int main(){ int t; cin>>t; while(t--){ string str; cin>>str; Solution ob; cout<<ob.palindromicPartition(str)<<" "; } return 0; } // } Driver Code Ends

  • @AmanSinghNaruka-g1n
    @AmanSinghNaruka-g1n 2 дні тому

    next level stuff

  • @rohitnandagawali1589
    @rohitnandagawali1589 2 дні тому

    bhai ka solution: problem link: leetcode.com/problems/permutations/ void helper(int start, vector<int>&nums, vector<vector<int>> & ans){ if(start==nums.size()){ ans.push_back(nums); return; } for(int i=start; i<nums.size();i++){ swap(nums[start], nums[i]); helper(start+1, nums, ans); swap(nums[start], nums[i]); } } vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> ans; int start=0; helper(start,nums, ans); return ans; }

  • @pratyusha2182
    @pratyusha2182 2 дні тому

    I understood this totally sir. Your way of teaching is reallyy amazing all my concepts are clear now. but i have a question. In the interviews, will they ask us to optimize/ shorten the length of the code ? because that way i might not be able to

  • @Prateek_Mantry
    @Prateek_Mantry 3 дні тому

    thank you so much.🙏

  • @alwayslearning1026
    @alwayslearning1026 3 дні тому

    #finished 👍

  • @deepanshuverma6237
    @deepanshuverma6237 3 дні тому

    Java code : public class SortArray { public static void main(String[] args) { List<Integer> list = new ArrayList<>(Arrays.asList(3,2,1,4,5,6,7)); System.out.println(sort(list)); } public static List<Integer> sort(List<Integer> list) { if (list.size() == 1) return list; int temp = list.remove(list.size() - 1); sort(list); insert(list, temp); return list; } public static List<Integer> insert(List<Integer> list, int temp) { if (list.isEmpty() || list.get(list.size() - 1) <= temp) { list.add(list.size(), temp); return list; } int value = list.remove(list.size() - 1); insert(list, temp); list.add(list.size(), value); return list; } }

  • @sumedhaghosh1265
    @sumedhaghosh1265 3 дні тому

    leetcode 438 class Solution { public: vector<int> findAnagrams(string s, string p) { unordered_map<char,int>mp; for(int i=0;i<p.size();i++) mp[p[i]]++; int i=0; int j=0; int count=mp.size(); int k=p.size(); vector<int>res; while(j<s.size()) { if(mp.find(s[j])!=mp.end()){ mp[s[j]]--; if(mp[s[j]]==0) count--; } if(j-i+1 < k) j++; else if(j-i+1 == k) { if(count==0) res.push_back(i); if (mp.find(s[i]) != mp.end()) { mp[s[i]]++; if (mp[s[i]] == 1) count++; } i++; j++; } } return res; } };

  • @souviksen5177
    @souviksen5177 3 дні тому

    Java Solution: class Solution { static ArrayList<Integer> list; public static ArrayList<Integer> increasingNumbers(int n) { list = new ArrayList<>(); ArrayList<Integer> temp = new ArrayList<>(); if(n == 1){ for(int i=0; i<10; i++) list.add(i); return list; } solve(list, temp, n, 0); return list; } static void solve(ArrayList<Integer> list, ArrayList<Integer> temp, int n, int start){ if(n == 0){ int ans = 0; for(int i=0; i<temp.size(); i++) ans = ans * 10 + temp.get(i); list.add(ans); } for(int i = start + 1; i<10; i++){ temp.add(i); solve(list, temp, n - 1, i); temp.remove(temp.size() - 1); } } }

  • @debajyotibhatta
    @debajyotibhatta 3 дні тому

    class Pair{ int num; int index; Pair(int x,int y){ num=x; index=y; } } class Solution { public int largestRectangleArea(int[] heights) { int[] left=LeftIndex(heights); int[] right=RightIndex(heights); int[] width=new int[heights.length]; for(int i=0;i<heights.length;i++){ width[i]=right[i]-left[i]-1; } int[] area=new int[heights.length];int max=Integer.MIN_VALUE; for(int i=0;i<heights.length;i++){ area[i]= width[i]*heights[i]; if(max<area[i]){ max=area[i]; } } return max; } public int[] LeftIndex(int[] h){ int[] left = new int[h.length]; Stack<Pair> stl = new Stack<>(); int pseudoindex = -1; for (int i = 0; i < h.length; i++) { if (stl.isEmpty()) { left[i] = pseudoindex; } else if (!stl.isEmpty() && stl.peek().num < h[i]) { left[i] = stl.peek().index; } else if (!stl.isEmpty() && stl.peek().num >= h[i]) { while (!stl.isEmpty() && stl.peek().num >= h[i]) { stl.pop(); } if (stl.isEmpty()) { left[i] = pseudoindex; } else { left[i] = stl.peek().index; } } stl.push(new Pair(h[i], i)); } return left; } public int[] RightIndex(int[] h){ int[] right = new int[h.length]; Stack<Pair> str = new Stack<>(); int pseudoindex = h.length; for (int i = h.length - 1; i >= 0; i--) { if (str.isEmpty()) { right[i] = pseudoindex; } else if (!str.isEmpty() && str.peek().num < h[i]) { right[i] = str.peek().index; } else if (!str.isEmpty() && str.peek().num >= h[i]) { while (!str.isEmpty() && str.peek().num >= h[i]) { str.pop(); } if (str.isEmpty()) { right[i] = pseudoindex; } else { right[i] = str.peek().index; } } str.push(new Pair(h[i], i)); } return right; } }

  • @YashBakadiya
    @YashBakadiya 3 дні тому

    7:13 😆

  • @831_sohampatra5
    @831_sohampatra5 4 дні тому

    Not good.

  • @Sudharshan-kd8tv
    @Sudharshan-kd8tv 4 дні тому

    The approach i tried in java int minmumSubSetDiff(int arr[], int n) { // first get subsetsum array response boolean[][] subSetSum = subSetSum(arr, n); boolean[] lastRow = subSetSum[n]; int sum1 = 0; int sum = calculateSum(arr); for (int i = (lastRow.length / 2); i >= 0 + 1; i--) { if (lastRow[i] == true) { sum1 = i; break; } } return sum - 2 * sum1; }

  • @me_luga8036
    @me_luga8036 4 дні тому

    Sir ! In which company do you work .

  • @shubhambag5
    @shubhambag5 4 дні тому

    which language you using?

  • @shyamkachhadiya4964
    @shyamkachhadiya4964 4 дні тому

    wow great problem, solved excellents, there's little maths involved but yea great explanation.

  • @a.gcrazy555
    @a.gcrazy555 4 дні тому

    Can we optimise this using memoization

  • @a.gcrazy555
    @a.gcrazy555 4 дні тому

    I have never seen this kind of detailed and clear explanation . of tough questions like this

  • @Divy2-zx4eo
    @Divy2-zx4eo 4 дні тому

    class Solution { public: vector <int> v_r; vector <int> v_l; stack <pair<int,int>> s_r; stack <pair<int,int>> s_l; vector<int> width; int area= 0; std::vector<int> nextSmallerRight(const std::vector<int>& heights){ int n = heights.size(); for(int i=n-1; i>=0; i--){ if(s_r.size()==0){ v_r.push_back(n); } else if(s_r.size()>0&& s_r.top().first<heights[i]){ v_r.push_back(s_r.top().second); } else if(s_r.size()>0&& s_r.top().first>=heights[i]){ while(s_r.size()>0&& s_r.top().first>=heights[i]){ s_r.pop(); } if(s_r.size()==0){ v_r.push_back(n); } else{ v_r.push_back(s_r.top().second); } } s_r.push({heights[i],i}); } std:: reverse(v_r.begin(), v_r.end()); return v_r; } std::vector<int> nextSmallerLeft(const std::vector<int>& heights) { int n = heights.size(); for(int i=0; i<n; i++){ if(s_l.size()==0){ v_l.push_back(-1); } else if(s_l.size()>0&& s_l.top().first<heights[i]){ v_l.push_back(s_l.top().second); } else if(s_l.size()>0&& s_l.top().first>=heights[i]){ while(s_l.size()>0&& s_l.top().first>=heights[i]){ s_l.pop(); } if(s_l.size()==0){ v_l.push_back(-1); } else{ v_l.push_back(s_l.top().second); } } s_l.push({heights[i],i}); } return v_l; } int largestRectangleArea(vector<int>& heights) { nextSmallerRight(heights); nextSmallerLeft(heights); for(int i=0;i<heights.size();i++){ width.push_back(v_r[i]-v_l[i]-1); } for(int i=0; i<heights.size(); i++){ area = std::max(area, heights[i]*width[i]); } return area; } }; Here is my code

  • @basujain8928
    @basujain8928 4 дні тому

    bhai tumhare concept bahut acche clear hai but bahut kachra or bakwas trike se likhte ho, samj nhi ata kaha code hai kaha algo,, aise kaise bnoge acche edutuber, or adha ghante ka time apne online communit ke nhi nikal skte kya ki ye backtracking ki video playlist complete krle, mai to ppori dekne hi aya tha, or ye code to likhr nhi kamse kam psudoocde to lik dia kro, ki jisko ppori video nhi dekni to bas code dekh ki age badh jae. agar meri ye baten manoge fir tum bahut acche teacher bnoge dsa ke utubepe

  • @Yash-afk
    @Yash-afk 5 днів тому

    Here's how i did it in Java: import java.util.*; class Pair { int key; int value; Pair(int key, int value) { this.key = key; this.value = value; } } class top_k_freq { public static void main(String[] args) { int[] arr = {1, 1, 1, 3, 2, 2, 4}; int k = 2; HashMap<Integer, Integer> hm = new HashMap<>(); for (int i : arr) { hm.put(i, hm.getOrDefault(i, 0) + 1); } // Step 2: Use a priority queue to find the top k frequent elements PriorityQueue<Pair> min_heap = new PriorityQueue<>(new Comparator<Pair>() { public int compare(Pair a, Pair b) { return Integer.compare(a.value, b.value); } }); for (Map.Entry<Integer, Integer> entry : hm.entrySet()) { min_heap.add(new Pair(entry.getKey(), entry.getValue())); if (min_heap.size() > k) { min_heap.poll(); } } // Step 3: Extract the results from the priority queue List<Integer> result = new ArrayList<>(); while (!min_heap.isEmpty()) { result.add(min_heap.poll().key); } // Since the smallest frequency elements were removed first, reverse the result list Collections.reverse(result); // Print the result System.out.println(result); } }

  • @yashvijay5762
    @yashvijay5762 5 днів тому

    bhai please yr app dsa ki videos continue upload kro apse acha explaination maine pure youtube pr nhi dekha pls brother🙏

  • @sandeepjaiswar4990
    @sandeepjaiswar4990 5 днів тому

    Mai likhunga kachara ho jayega, BC(base condition) and drawing rat so funny🤣

  • @lifeNfreek
    @lifeNfreek 5 днів тому

    why the first solve array we're passing same i and k value, don't you thkink both the mattrix have same value?

  • @sumedhaghosh1265
    @sumedhaghosh1265 5 днів тому

    leetcode 2461 using hashmap to remove duplicate elements class Solution { public: long long maximumSubarraySum(vector<int>& nums, int k) { long long n=nums.size(); int i=0; int j=0; long long sum=0; long long maxsum=0; unordered_map<int,int>mp; while(j<n) { mp[nums[j]]++; sum+=nums[j]; if(j-i+1 < k) j++; else if(j-i+1 == k) { if(mp.size()==k) maxsum=max(maxsum,sum); sum=sum-nums[i]; mp[nums[i]]--; if(mp[nums[i]]==0) mp.erase(nums[i]); i++; j++; } } return maxsum; } };

  • @shantahiremath7313
    @shantahiremath7313 5 днів тому

    Thank you so much, one of the best videos on sliding window. Easy to understand and best explanation.

  • @Aditya_6996
    @Aditya_6996 5 днів тому

    thanks bhaiya , amazing teaching skills !

  • @me_luga8036
    @me_luga8036 5 днів тому

    Yeh code work nahi kar raha hain

  • @Abstract.x
    @Abstract.x 5 днів тому

    Python solution: def cutRod(self, price, n): dp = [[0 for _ in range(n+1)] for _ in range(n+1)] # dp[i][j] = max value obtained by cutting rod of length j into pieces considering the first i lengths for i in range(1, n+1): for j in range(1, n+1): if i > j: dp[i][j] = dp[i - 1][j] else: includeCut = price[i - 1] + dp[i][j - i] excludeCut = dp[i - 1][j] dp[i][j] = max(includeCut, excludeCut) return dp[n][n] However, this runs out of time for some test cases since it can be optimized with 1D array for dp. Here is optimized approach: class Solution: def cutRod(self, price, n): dp = [0] * (n + 1) for i in range(1, n + 1): for j in range(i, n + 1): include = price[i - 1] + dp[j - i] exclude = dp[j] dp[j] = max(include, exclude) return dp[n]

  • @pd-oh3yy
    @pd-oh3yy 5 днів тому

    Bhaiya please weak mai atleast ek video dal diya karo DSA/CP related

  • @divinity8683
    @divinity8683 5 днів тому

    no one better than u

  • @divinity8683
    @divinity8683 5 днів тому

    graphhhhh please

  • @vaibhavsahay1323
    @vaibhavsahay1323 5 днів тому

    just in case u people needed a code in java.... import java.util.*; public class sw2 { public static void minneg(int arr[], int k) { ArrayList<Integer> list = new ArrayList<>(); int i = 0, j = 0; while (j < arr.length) { if (arr[j] < 0) { list.add(arr[j]); } if (j - i + 1 == k) { if (!list.isEmpty()) { System.out.println(list.get(0)); } else { System.out.println(0); } if (arr[i] < 0 && !list.isEmpty() && arr[i] == list.get(0)) { list.remove(0); } i++; } j++; } } public static void main(String[] args) { int arr[] = {12, -1, -7, 8, -15, 30, 16, 28}; int k = 3; minneg(arr, k); } }

  • @vaibhavsahay1323
    @vaibhavsahay1323 5 днів тому

    this is the code just in case.... import java.util.*; public class slidingwindow1 { public static int maxsum(int arr[],int k) { int i=0; int j=0; int sum=0; int max = Integer.MIN_VALUE; while(j<arr.length) { sum=sum+arr[j]; if(j-i<k){ j++; } else if(j-i==k) { max=Math.max(sum,max); sum=sum-arr[i]; i++; j++; } } return sum; } public static void main(String[] args) { int arr[]={1,2,3,4,5}; int k=3; int result = maxsum(arr, k); System.out.println("Maximum sum of subarray of size " + k + " is: " + result); } }

  • @akashkumarprajapati9874
    @akashkumarprajapati9874 5 днів тому

    Hey Google :- How to watch all the videos in 1 minutes, 1 by 1 without skipping and high speed. I want to become master of dp in 1 mintues 😅😅

  • @kiwimoma1799
    @kiwimoma1799 6 днів тому

    we need series for graph T.T