![Aditya Verma](/img/default-banner.jpg)
- 148
- 24 459 080
Aditya Verma
India
Registrace 30. 06. 2018
I am a SDE 2 @ Flipkart.
Through this Channel I aim to help thousands of student who are preparing for their Interview but couldn't find explanation good enough to clear their doubts. I faced the same problem when I was preparing for my Interviews. Here on this channel I explained the concepts as I studied them which eventually landed me Intern + Full Time offer in Flipkart.
In this channel I tried my best to provide an alternative to mugging up the things and showed how really to grasp concepts behind a problem.
Through this Channel I aim to help thousands of student who are preparing for their Interview but couldn't find explanation good enough to clear their doubts. I faced the same problem when I was preparing for my Interviews. Here on this channel I explained the concepts as I studied them which eventually landed me Intern + Full Time offer in Flipkart.
In this channel I tried my best to provide an alternative to mugging up the things and showed how really to grasp concepts behind a problem.
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.
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.
zhlédnutí: 13 960
Video
12 Rat in a Maze Problem
zhlédnutí 8KPřed 5 měsíci
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
zhlédnutí 6KPřed 5 měsíci
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
zhlédnutí 6KPřed 5 měsíci
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
zhlédnutí 13KPřed 7 měsíci
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
zhlédnutí 13KPřed 7 měsíci
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
zhlédnutí 10KPřed 7 měsíci
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
zhlédnutí 20KPřed 7 měsíci
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
zhlédnutí 12KPřed 7 měsíci
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
zhlédnutí 16KPřed 8 měsíci
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
zhlédnutí 17KPřed 8 měsíci
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
zhlédnutí 40KPřed 8 měsíci
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
zhlédnutí 59KPřed 8 měsíci
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?
zhlédnutí 48KPřed 8 měsíci
Backtracking series starts tomorrow
Minimum Window Substring | Variable Size Sliding Window
zhlédnutí 195KPřed 3 lety
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
zhlédnutí 87KPřed 3 lety
Pick Toys | An Interesting Sliding Window Problem
Longest Substring With Without Repeating Characters | Variable Size Sliding Window
zhlédnutí 136KPřed 3 lety
Longest Substring With Without Repeating Characters | Variable Size Sliding Window
Longest Substring With K Unique Characters | Variable Size Sliding Window
zhlédnutí 154KPřed 3 lety
Longest Substring With K Unique Characters | Variable Size Sliding Window
Variable Size Sliding Window General Format
zhlédnutí 109KPřed 3 lety
Variable Size Sliding Window General Format
Variable Size Sliding Window | Largest Subarray of sum K | Part1
zhlédnutí 147KPřed 3 lety
Variable Size Sliding Window | Largest Subarray of sum K | Part1
Maximum of all subarrays of size k | Sliding Window
zhlédnutí 215KPřed 3 lety
Maximum of all subarrays of size k | Sliding Window
Count Occurrences Of Anagrams | Sliding Window
zhlédnutí 217KPřed 3 lety
Count Occurrences Of Anagrams | Sliding Window
How To Debug Your Code | How To Solve Any Coding Problem In Your Interview Part 3
zhlédnutí 35KPřed 3 lety
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
zhlédnutí 42KPřed 3 lety
Significance Of The Constraints | How To Solve Any Coding Problem In Your Interview Part 2
Giveaway of 2000 INR To The Community | Aditya Verma
zhlédnutí 7KPřed 3 lety
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
zhlédnutí 103KPřed 3 lety
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
zhlédnutí 247KPřed 3 lety
First Negative Number in every Window of Size K | Sliding Window
Maximum Sum Subarray of size K | Sliding Window
zhlédnutí 308KPřed 3 lety
Maximum Sum Subarray of size K | Sliding Window
very underrated , helped alot thanks...
JAVA : public class Print_SubSets { static List<String> list = new ArrayList<>(); public static void main(String[] args) { String str = "abc"; printSubsets3(new StringBuilder(""), str, 0); System.out.println(list); list.clear(); printSubsets2("", str, 0); System.out.println(list); list.clear(); printSubsets("", str); System.out.println(list); } @Description("Using backtracking ") private static void printSubsets3(StringBuilder op, String ip, int index) { if (index == ip.length()) { list.add(op.toString()); return; } printSubsets3(op, ip, index + 1); op.append(ip.charAt(index)); printSubsets3(op, ip, index + 1); op.deleteCharAt(op.length() - 1); } @Description("Using recursion, while input value is not updated") private static void printSubsets2(String op, String ip, int index) { if (index == ip.length()) { list.add(op); return; } printSubsets2(op, ip, index + 1); printSubsets2(op + ip.charAt(index), ip, index + 1); } @Description("Using recursion, while input is updated") private static void printSubsets(String op, String ip) { if (ip.isEmpty()) { list.add(op); return; } printSubsets(op, ip.substring(1)); printSubsets(op + ip.charAt(0), ip.substring(1)); } }
How would we refactor the base case if we're allowed to have 0 as value in the array?
This guy is again gone😂
bhaiya graph ka bhi video banayo n , plese
Really need this but in English please. Please add some subs or something... Looks quite good but the language barrier makes it hard for me
leetcode ka example poora dry run karke khud se samajh aaya code ka logic thank you bhai !!
Solved on my own ❤
understood sir thanks
Loved your video . Too good .👏❤
here is the code: int change(int amount, vector<int>& coins) { int t[coins.size()+1][amount+1]; for(int i=0;i<coins.size()+1;i++){ for(int j=0;j<amount+1;j++){ if(i==0) t[i][j]=0; if(j==0){ t[i][j]=1; } } } for(int i=1;i<coins.size()+1;i++){ for(int j=1;j<amount+1;j++){ if(coins[i-1]<=j){ t[i][j]=t[i][j-coins[i-1]]+t[i-1][j]; } else{ t[i][j]=t[i-1][j]; } } } return t[coins.size()][amount]; } };
I did the same on leetcode but it's still giving me tle class Solution { public int minCut(String str) { int n = str.length(); int[][] dp = new int[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(dp[i], -1); } return mcm(str, 0, n - 1, dp); } static boolean isPalindrome(String str, int i, int j) { while (i < j) { if (str.charAt(i) != str.charAt(j)) { return false; } i++; j--; } return true; } private static int mcm(String str, int i, int j, int[][] dp) { if (i >= j || isPalindrome(str, i, j)) { return 0; } if (dp[i][j] != -1) { return dp[i][j]; } int min = Integer.MAX_VALUE; for (int k = i; k < j; k++) { int c1 = (dp[i][k] != -1) ? dp[i][k] : mcm(str, i, k, dp); int c2 = (dp[k + 1][j] != -1) ? dp[k + 1][j] : mcm(str, k + 1, j, dp); int temp = 1 + c1 + c2; if (temp < min) { min = temp; } } dp[i][j] = min; return min; } } can anyone help?
Love your content bhai ❤when I need revision I blindly open ur video
understood sir
we can also find mid by :-> mid = pow(2,N-2); , jst simple maths
This one was a bit trickier than the rest but managed to code it after a few attempts. Amazing playlist, I have personally seen a lot of question based on the limited patterns covered in this playlist! Very helpful!
import java.util.*; class HelloWorld { public static void main(String[] args) { Stack<Integer> arr = new Stack<Integer>(); arr.push(4); arr.push(1); arr.push(3); arr.push(0); arr= sort(arr); while(!arr.isEmpty()){ System.out.print(arr.pop()); } } public static Stack<Integer> sort(Stack<Integer> arr){ if(arr.size()<=1) return arr; int tem=arr.pop(); sort(arr); insert(arr,tem); return arr; } public static void insert(Stack<Integer> arr,int temp){ if (arr.isEmpty() || temp >= arr.peek()) { arr.push(temp); return;} int last = arr.pop(); insert(arr, temp); arr.push(last); } }
import java.util.*; class HelloWorld { public static void main(String[] args) { ArrayList<Integer> arr = new ArrayList<Integer>(Arrays.asList(3,2,5,9,69,1)); arr= sort(arr); System.out.print(arr); } public static ArrayList<Integer> sort(ArrayList<Integer> arr){ if(arr.size()<=1) return arr; int tem=arr.get(arr.size()-1); arr.remove(arr.size()-1); sort(arr); insert(arr,tem); return arr; } public static void insert(ArrayList<Integer> arr,int temp){ if (arr.isEmpty() || temp >= arr.get(arr.size() - 1)) { arr.add(temp); return;} int last = arr.remove(arr.size() - 1); insert(arr, temp); arr.add(last); } }
JavaScriptCode For Recursive SortArray:- function sortArray(arr, s, end) { if (s >= end) { return arr; } let lastVal = arr.pop(); sortArray(arr, s, end - 1); insertVal(arr, lastVal); } function insertVal(arr, lastVal) { if (arr.length === 0 || arr[arr.length - 1] <= lastVal) { arr.push(lastVal); return; } let lastSortedVal = arr.pop(); insertVal(arr, lastVal); arr.push(lastSortedVal); } let arr = [1, 0, 5, 2]; let s = 0; let end = arr.length - 1; sortArray(arr, s, end); console.log(arr);
how can we eleminate the whole side - here is easy explaination for eg 1,2,20,5,12,18,20,21,211 here 12 is mid and there is no peak in right of it but 20 is peak element in left, however we have discarded left side. then the ans will be 211 , as it it large from its left and has no number after it and in case in place of 211 we have any number lesser than 21 than by the same approach we would hv got answer in ryt side tht is 21
Thank you bhai for all the videos. U make it look so easy..Tysm..and PLEASE PLEASE PLEASE..continue teaching other concepts as well..
I have a simple question, if I use memoization will it even calculate the values for [n, w-1, w-2,...]? Because memoization uses optimal approach to reach the solution of one particular problem and doesn't necessarily solve all overlapping subproblems that might not be related to the solution we're asking for.
One better way (suits the format more ), is when we get left value, at that time only we compare it with 0, if left is <0 we simply discard it and make it 0. int left = max(0,solve(root->left,res,curPath,bestPath)); int right =max(0,solve(root->right,res,curPath,bestPath)); then we can do similar res = max(res,root->val +left + right); return root->val + max(left,right);
Watching this in 2024... Not getting vedios better than this❤❤
JAVA CODE public void help(int open,int close, String output, List<String>ans) { if(open==0 && close==0) { ans.add(output); return ; } if(open==close) { help(open-1,close,output +'(',ans); return; } if(open==0) { help(open,close-1,output+')',ans); return; } if(close==0) { help(open-1,close,output +'(',ans); return; } help(open-1,close,output+'(',ans); help(open,close-1,output+')',ans); } public List<String> generateParenthesis(int n) { List<String>ans=new ArrayList<>(); String output=""; help(n,n,output,ans); return ans; } LEETCODE QUE-22
#include <vector> using namespace std; vector<long long> printFirstNegativeInteger(long long int A[], long long int N, long long int k) { vector<long long> final; vector<long long> neg; // To store indices of negative numbers int i = 0, j = 0; while (j < N) { // Add current element to the vector if it's negative if (A[j] < 0) neg.push_back(j); // When the window size is less than k if (j - i + 1 < k) { j++; } // When the window size is exactly k else if (j - i + 1 == k) { // If vector is empty, it means no negative number in the current window if (neg.empty()) final.push_back(0); else final.push_back(A[neg.front()]); // The first negative number in the window // Slide the window if (!neg.empty() && neg.front() == i) neg.erase(neg.begin()); // Remove the element which is out of this window i++; j++; } } return final; }
We can think of the array as longest common substring ending with those indicies
Did not immediately solve this ques. Was making some trivial mistake. My approach: int lengthOfLongestSubstring(string s) { int n=s.size(); int j = 0; int i = 0; int ans = 0; map <char ,int> mp; while (j < n) { mp[s[j]]++; if(mp.size()==j-i+1){ ans=max(ans,j-i+1); } while(mp.size()<j-i+1){ mp[s[i]]--; if(mp[s[i]]==0){ mp.erase(s[i]); } i++; } j++; } return ans; }
a better format could be this: int start = 0; int end = 0; while (end < size) { // calculations if (....== k) { // conditions/calculations } else if (... > k) { while (... > k && start < end) { // do something start++; } } end++; } // return something
I just watched the first few lectures regarding the idea behind fixed size and variable size sliding window, and now i am solving problems on my own without checking the video out! Really helpful! Here is my implementation for the above question: simply applied the variable window template and used a frequency array to keep a track of the occurrences of each character. int longestKSubstr(string s, int k) { int n=s.size(); int i=0;int j=0; vector <int> freq(27,0); int ans=-1; while(j<n){ int count=0; freq[s[j]-'a']++; for(int k=0;k<27;k++){ if(freq[k]>0){ count++; } } if(count==k){ ans=max(ans,j-i+1); } while(count>k){ freq[s[i]-'a']--; if(freq[s[i]-'a']==0){ count--; } i++; } j++; } return ans; }
bhaiya aap dsa ke jhonny sins ho sare questions pel dete ho
MY JAVA SOLUTION public void help(String s,String output,int index, List<String>ans){ if(index==s.length()) { ans.add(output); return; } help(s, output + Character.toUpperCase(s.charAt(index)),index+1,ans); help(s,output +Character.toLowerCase(s.charAt(index)) ,index+1,ans); } public List<String> letterCasePermutation(String s) { List<String>ans=new ArrayList<>(); String output=""; help(s,output,0,ans); HashSet<String>st=new HashSet<>(); for(int i=0;i<ans.size();i++) { st.add(ans.get(i)); } List<String>ans2=new ArrayList<>(); for(var e:st) { ans2.add(e); } return ans2; } }
I hv one more approach we can use count of subset with target sum except we have 3 possibilities : add, substract and exclude. def subset_sum_with_sign_change ( nums : list , n : int, target_sum : int): if target_sum == 0: return True if n == 0: return False return subset_sum_with_sign_change ( nums , n - 1, target_sum - nums [n - 1] ) or \ subset_sum_with_sign_change ( nums , n - 1, target_sum ) or \ subset_sum_with_sign_change ( nums , n - 1, target_sum + nums [ n - 1 ] ) def dp_subset_sum_with_sign_change ( nums : list, n : int, target_sum : int ): dp = [ [ 0 for _ in range ( sum ( nums ) + 1 ) ] for _ in range ( n + 1 ) ] def initialize_dp_table(): nonlocal dp for num_index in range ( n + 1 ): for subsum in range ( sum ( nums ) + 1 ): if num_index == 0 and subsum != 0: dp [ num_index ] [ subsum ] = 0 if subsum == 0 or subsum == sum(nums): dp [ num_index ] [ subsum ] = 1 def fill_dp_table(): nonlocal dp for num_index in range ( 1 , n + 1 ): for subsum in range ( 1 , target_sum + 1 ): dp [ num_index ][ subsum ] = dp [ num_index - 1 ] [ subsum - nums [ num_index - 1 ] ] +\ dp [ num_index - 1 ] [ subsum + nums [ num_index - 1 ] ] +\ dp [ num_index - 1 ] [ subsum ] initialize_dp_table() fill_dp_table() for row in dp: print ( row ) return dp [ n ] [ target_sum ]
Sum up: 40:36
i will watch full playlist of sliding window...☺ it's so interesting
int i=0,j=0; vector <int> ans; int n=A.size(); if(B>n){ return ans; } else if(B==n){ ans.push_back(*max_element(A.begin(),A.end())); return ans; } multiset <int> s; while(j<n){ s.insert(A[j]); if(j-i+1==B){ ans.push_back(*s.rbegin()); s.erase(s.find(A[i])); i++; } j++; } return ans; This was my solution for this question. I use a set to store the max elements in the window.
Your way of explanation is very easy to understand way best then paid ppl...... plz make such more videos 🤗
What a video! Amazing bro ❤❤
Would it be a problem if we did not write elseif and straightaway wrote return knapsack skipping condition?
Thank you, Aditya, I have cracked one of the Google and Amazon interviews by watching your videos. Thank you again for clarifying the concepts.
after watching this video,I feel like ab toh apun hi dp ka bhagwan hai thankyou so much ,I am able to visualize everything about memoisation and tabulation now
very nice explanation sir
bhaiya tree ki playlist bana do. I have tried studying from various sources, but I'm not understanding it. If anyone knows of any good channels for learning trees, please reply. I have tried learning from Striver, but it hasn't been much help.
Done🔥🔥
Main last row part concept starts from here 00:31:00
Note down at 10:24 for What is subproblem actully?
Main concept from 15:00
glt logic hai 11 12 13 14 pr chlao 4 5 6 7 0 1 2 pr chalao leetcode pr serch kro find minimumn in sorted array
Code in Java using recursion and memoization- public int lcsubstring(String str1,String str2,int m, int n){ if(m==0||n==0){ memory[m][n]=0; return 0; } if(memory[m][n]!=-1){ return memory[m][n]; } if(str1.charAt(m-1)==str2.charAt(n-1)){ return memory[m][n]=1+lcsubstring(str1,str2,m-1,n-1); } lcsubstring(str1,str2,m-1,n); lcsubstring(str1,str2,m,n-1); return 0; } public static void main(String[] args) { String str1= "AGGTAB"; String str2= "AGxTAc"; LongestCommonSequence longestCommonSequence= new LongestCommonSequence(str1.length(),str2.length()); longestCommonSequence.lcsubstring(str1,str2,str1.length(),str2.length()); int max=-999; // Finding the maximum in the memoized table. for (int i=0;i<longestCommonSequence.memory.length;i++){ for (int j=0;j<longestCommonSequence.memory[i].length;j++){ max=Integer.max(max,longestCommonSequence.memory[i][j]); } } System.out.println(max); }
i did this but without backtracking. honestly the recursive tree method u taught is the easiest one for me I am very comfortable with that.