Tip 1 : Data Structures
Tip 2 : Interview Experience by my seniors
Tip 3 : Project
Tip 1 : Must have good project
Tip 2 : Mention your skills



A coding round of 3 minutes containing one Question of dynamic programming



The given string st = AABCBDC.

As you can see there are two repeating longest subsequences “ABC” with the same character but different position. Therefore the required answer is ‘3’ as the length of “ABC” is 3.
int LongestRepeatingSubsequence(string str){
int n=str.length();
string str1=str;
string str2=str;
int t[n+1][n+1];
for(int i=0;i for(int j=0;j if(i==0){
t[i][j]=0;
}
if(j==0){
t[i][j]=0;
}
}
}
for(int i=1;i for(int j=1;j if(str1[i-1]==str2[j-1] && i!=j){
t[i][j]=1+t[i-1][j-1];
}
else{
t[i][j]=max(t[i-1][j],t[i][j-1]);
}
}
}
return t[n][n];
}
Interviewer was very good he asked some basic question about me and my college and then gave me two dsa problem to solve



Consider below matrix of characters,
[ 'D', 'E', 'X', 'X', 'X' ]
[ 'X', 'O', 'E', 'X', 'E' ]
[ 'D', 'D', 'C', 'O', 'D' ]
[ 'E', 'X', 'E', 'D', 'X' ]
[ 'C', 'X', 'X', 'E', 'X' ]
If the given string is "CODE", below are all its occurrences in the matrix:
'C'(2, 2) 'O'(1, 1) 'D'(0, 0) 'E'(0, 1)
'C'(2, 2) 'O'(1, 1) 'D'(2, 0) 'E'(3, 0)
'C'(2, 2) 'O'(1, 1) 'D'(2, 1) 'E'(1, 2)
'C'(2, 2) 'O'(1, 1) 'D'(2, 1) 'E'(3, 0)
'C'(2, 2) 'O'(1, 1) 'D'(2, 1) 'E'(3, 2)
'C'(2, 2) 'O'(2, 3) 'D'(2, 4) 'E'(1, 4)
'C'(2, 2) 'O'(2, 3) 'D'(3, 3) 'E'(3, 2)
'C'(2, 2) 'O'(2, 3) 'D'(3, 3) 'E'(4, 3)
int countOccurrences(char *str,
string word)
{
char *p;
vector a;
p = strtok(str, " ");
while (p != NULL)
{
a.push_back(p);
p = strtok(NULL, " ");
}
int c = 0;
for (int i = 0; i < a.size(); i++)
if (word == a[i])
c++;
return c;
}



1. Both STR and PTR consist of English uppercase letters.
2. Length of string 'STR' will always be greater than or equal to the length of string ‘PTR’.
3. In case, there is no anagram substring, then return an empty sequence.
4. In case of more than one anagrams, return the indices in increasing order.
bool areAnagram(string str1, string str2)
{
int n1 = str1.length();
int n2 = str2.length();
if (n1 != n2)
return false;
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
for (int i = 0; i < n1; i++)
if (str1[i] != str2[i])
return false;
return true;
}



If the given input string is "Welcome to Coding Ninjas", then you should return "Ninjas Coding to Welcome" as the reversed string has only a single space between two words and there is no leading or trailing space.
class Solution {
private:
void reverse(string &s, int i, int j){
while(i char temp=s[i];
s[i++]=s[j];
s[j--]=temp;
}
}
public:
string reverseWords(string &s) {
int i=0, j=0;
int l=0;
int len=s.length();
int wordcount=0;
while(true){
while(i if(i==len) break;
if(wordcount) s[j++]=' ';
l=j;
while(i reverse(s,l,j-1);
wordcount++;
}
s.resize(j);
reverse(s,0,j-1);
return s;
}
};
There are 4 persons (A, B, C and D) who want to cross a bridge in night.
A takes 1 minute to cross the bridge.
B takes 2 minutes to cross the bridge.
C takes 5 minutes to cross the bridge.
D takes 8 minutes to cross the bridge.
There is only one torch with them and the bridge cannot be crossed without the torch. There cannot be more than two persons on the bridge at any time, and when two people cross the bridge together, they must move at the slower person’s pace.
Step 1 : A and B cross the bridge. A comes back. Time taken 3 minutes. Now B is on the other side.
Step 2 : C and D cross the bridge. B comes back. Time taken 8 + 2 = 10 minutes. Now C and D are on the other side.
Step 3 : A and B cross the bridge. Time taken is 2 minutes. All are on the other side.
Total time spent: 3 + 10 + 2 = 15 minutes.
Find the last ball to remain after the entire process
Problem Statement: You have 20 Red and 16 Blue balls in a bag. You pull out 2 balls one after another. If the balls are of the same color, then you replace them with a Blue ball – but if they are of different color, you replace them with a Red ball. Once you take out the balls, you do not put them back in the bag – so the balls keep reducing. What would be the color of the last ball remaining in the bag?
Answer: Red Balls
Observations:
Blue balls can only be reduced by two and that too if the 1st condition is satisfied, i.e., if you choose both blue balls, then they are replaced by a single red ball. In no other ways you can reduce blue balls. Red balls can be reduced by one on the basis of 2nd condition if you choose both different balls and on the basis of 1st condition if you choose both red balls.
Now, because there are an even number of blue balls and blue balls can only be reduced by two, you will end up with either 0 or 2 or 4…(even number) blue balls in the bag at any point during the replacement process. There will never be a situation in which the bag contains an odd number of blue balls. As a result, the last ball in the bag will be a red ball in any combination of replacements.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
How do you remove whitespace from the start of a string?