Nutanix MTS 4 | Bangalore |Jan 2021 | Approach
Anonymous User
1237

Round 1

Design a Plagiarism algorithm where system is recording keystrokes of input given by Student1 and Student2
This was the abstract question asked and no other information was given.

Points to remember(cleared after having to-fro conversation):

  1. Only Keystrokes were given and not the full final text

  2. I took keystorkes in a char[] & important part was to consider backslash as well, this makes problem interesting
    Keystrokes means Let say char[] = 'a','b','c','/','/'

Approach 1

boolean checkIfPlagiarism(char[] txt1, char[] txt2){
}

Brute-force Using Stack putting all characters in stack and removing top character when backslash occur
This will be O(L+M) TC and SC where L - number of characters in txt1 and M - number of chars in txt2

As per interviewer, its time consuming and i need to think something better. Its not real-time as well.

Approach 2

// edge cases not covered, basic pseudo code

void compute(char[] txt){
		int j;
    for(int i=0;i<txt.length;i++){
	   if(txt[i]=='/'){
					j=i-1;					
    }else if(j!=0){
    	char[j++]=char[i];
    }
  }
}

Here i proposed to have two pointers and final string would be (0,j)and rest will be having garbage chars.

Cons - changing char[] as per above algo

Expectation
Interviewer was expecting to solve this without using any other Data structure(Approach 1) and without changing char[] as well

Can someone help me how to implement this as per expectation and if there is any other way this problem can be approached(key-strokes was focussed lot of times)

Thanks in advance

Comments (2)