Tip 1 : Practice Atleast 250 Questions from a standard dsa sheet
Tip 2 : Have good project in resume
Tip 1:Mention all technical skills
Tip 2:have good project



1. Delete a character
2. Replace a character with another one
3. Insert a character
Strings don't contain spaces in between.
Approach
Here's the step-by-step approach:
Initialize a matrix dp of size (m+1) x (n+1), where m and n are the lengths of word1 and word2, respectively.
Fill in the base cases:
dp[i][0] = i for i from 0 to m.
dp[0][j] = j for j from 0 to n.
For each i from 1 to m and each j from 1 to n, compute the value of dp[i][j] as follows:
If word1[i-1] is equal to word2[j-1], then dp[i][j] = dp[i-1][j-1]. Otherwise, dp[i][j] is the minimum of the following three values plus 1:
a) dp[i][j-1], which represents inserting a character in word1.
b) dp[i-1][j], which represents deleting a character in word1.
c) dp[i-1][j-1], which represents replacing a character in word1.
Return dp[m][n], which is the minimum number of operations required to convert word1 to word2.
Complexity
Time complexity:
The time complexity of the solution is O(mn), where m and n are the lengths of the input strings. This is because we need to fill in an (m+1) x (n+1) matrix, and each cell takes constant time to fill.
Space complexity: O(mn)
Code
class Solution {
public:
int minDistance(string word1, string word2) {
int m = word1.length();
int n = word2.length();
vector> dp(m+1, vector(n+1));
for (int i = 0; i <= m; i++) {
dp[i][0] = i;
}
for (int j = 0; j <= n; j++) {
dp[0][j] = j;
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (word1[i-1] == word2[j-1]) {
dp[i][j] = dp[i-1][j-1];
} else {
dp[i][j] = 1 + min({dp[i][j-1], dp[i-1][j], dp[i-1][j-1]});
}
}
}
return dp[m][n];
}
};



Gcd of two numbers (X, Y) is defined as the largest integer that divides both ‘X’ and ‘Y’.
#include
using namespace std;
int GCD[1002][1002];
bool vis[1002][1002][2];
int dp[1002][1002][2];
void pre()
{
for ( int i = 1; i <= 1000; i++ ) {
for ( int j = 1; j <= i; j++ ) {
GCD[i][j] = GCD[j][i] = __gcd(i,j);
}
}
return;
}
int f(int a, int b, int turn)
{
if ( turn == 0 ) {
if ( a == 1 ) return 0;
}
if ( turn == 1 ) {
if ( b == 1 ) return 0;
}
if ( vis[a][b][turn] ) return dp[a][b][turn];
vis[a][b][turn] = true;
int ans = 0;
if ( turn == 0 ) {
ans |= (!f(a,b-1,turn^1));
if ( GCD[a][b] != 1 ) ans |= (!f(a,b/GCD[a][b],turn^1));
}
else {
ans |= (!f(a-1,b,turn^1));
if ( GCD[a][b] != 1 ) ans |= (!f(a/GCD[a][b],b,turn^1));
}
dp[a][b][turn] = ans;
return ans;
}
int main() {
int t,A,B;
pre();
cin >> t;
while ( t-- ) {
cin >> A >> B;
if(A==1 && B==1)
cout<<"Draw"< else if(A==1)
cout<<"Prateek"< else if(B==1)
cout<<"Gautam"< else{
if ( f(A,B,0) ) cout << "Gautam"< else cout << "Prateek"< }
}
return 0;
}



Two strings are said to be anagram if they contain the same characters, irrespective of the order of the characters.
If 'STR1' = “listen” and 'STR2' = “silent” then the output will be 1.
Both the strings contain the same set of characters.
class Solution {
public:
bool isAnagram(string s, string t) {
int arr[256]={0};
for(int i=0;i {
arr[s[i]]++;
}
for(int i=0;i {
arr[t[i]]--;
}
for(int i=0;i<256;i++)
if(arr[i]!=0)
return false;
return true;
}
};



Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
2 is written as II in the roman numeral, just two one’s added together.
12 is written as XII, which is simply X(ten) + II(one+one).
The number 27 is written as XXVII, which is XX + V + II.
Roman numerals are usually written largest to smallest from left to right.
However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four.
The same principle applies to the number nine, which is written as IX.
There are six instances where subtraction is used:
I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
class Solution {
public:
string intToRoman(int num) {
vector roman({"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"});
vector number({1,4,5,9,10,40,50,90,100,400,500,900,1000});
int size=roman.size()-1;
string ans="";
while(num>0)
{
while(number[size]<=num)
{
ans+=roman[size];
num-=number[size];
}
size--;
}
return ans;
}
};



I was not able to implement this during my interview

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?