Pergunta de entrevista da empresa X

1. Check if the expression is valid (simple valid parenthesis problem) 2. Generate valid permutations of expressions based on the count of parenthesis pair 3. Check if two strings are One Edit distance away.

Resposta da entrevista

Sigiloso

3 de abr. de 2016

boolean checkEditOneDiff(String str1, String str2) { int n = str1.length(); int m = str2.length(); if (Math.abs(n - m) > 1) { return false; } int diffCount = 0; int inxA = 0, inxB = 0; while (inxA n) { // found only one different character inxA++; } else if (m < n) { inxB++; } else { // same size inxA++; inxB++; } // Increment count of edits diffCount++; } else { // same inxA++; inxB++; } } // if last character is different if (inxA < m || inxB < n) { diffCount++; } return diffCount == 1; }