Turing Developers Technical Interviews [AMA]
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2020-01-13Added By Anonymous
Source: Link
Turing | Developers | Technical Interviews | unknown | unknown
Hi!
This my first post on hear and I've just completed the Algorithm Tests and MCQ's feel free to ask me anything and also if you have interviewed at Turing as well I'd love to know how your experience was!
Here's one of the questions I am allowed to share that I encountered in the Interview that's also on LeetCode.
https://leetcode.com/problems/substring-with-concatenation-of-all-words/
Hi!
This my first post on hear and I've just completed the Algorithm Tests and MCQ's feel free to ask me anything and also if you have interviewed at Turing as well I'd love to know how your experience was!
Here's one of the questions I am allowed to share that I encountered in the Interview that's also on LeetCode.
https://leetcode.com/problems/substring-with-concatenation-of-all-words/
/**
* @param {string} initial
* @param {string} goal
* @return {number}
*/
function minimumConcat(initial, goal) {
//Put your code here.
let count = 0;
let sequence = '';
//Create a pattern
initial.split('').map(letter => {
sequence = sequence + letter
});
//These iterators are basically the meat of the whole thing
//Thought it would be a better approach to convert the letters
//Into UTF-16 codes and working on them in that form
//Just as if I was doing a Cypher problem.
let iterator = Array.apply(null, Array(26)).map(Number.prototype.valueOf, 0), secondIter = Array.apply(null, Array(26)).map(Number.prototype.valueOf, 0);
//Convert it into something RegExp can evaluate
sequence = "^[" + sequence + "]*$";
//Check if the initial string ever has any hope of matching the goal string
if (!RegExp(sequence).test(goal)) return -1;
for (let i = 0; i < initial.length; i++) {
iterator[initial.charCodeAt(i) - 97]++;
}
for (let i = 0; i < goal.length; i++) {
secondIter[goal.charCodeAt(i) - 97]++;
}
//Compute the difference of the iterators
for (let i = 0; i < 26; i++) {
count += Math.abs(iterator[i] - secondIter[i]);
}
//Here ya go!
return count;
}
console.log(minimumConcat("abc", "abcbc"));