DEV Community


Posted on

a good example why tech companies test leetcode style questions.

Today I came across a question that is simple enough for most developers to solve fast, but just slightly complex enough to worth a little bit of discussion. I believe this questions, and my answer to it, is a pretty good demonstration why leetcode style interview exists. Let's look at the problem first:

The real problem at hand is how do you confirm whether two strings are representationally the same. Representationally, sorry for the unclear diction, because you can transform the strings into a representations of the order of appearance and how many of different kinds in each word.

so essentially, a good way to show an isomorphic representation of a string would be like:
egg = 122
add = 122
therefore egg and add are isomorphic

isomorphic = 1234356718;

Please see code below:

var isIsomorphic = function(s, t) {
    if (!s || !t) return false;
    if(s.length !== t.length) return false;

    let sMap = {};
    let tMap = {};
    let sNumString = '';
    let tNumString = '';
    let currentS = '';
    let currentT = ''
    for (let i=0; i<s.length; i++) {
        currentS = s[i];
        currentT = t[i];

        if(!sMap[currentS]) {
            sMap[currentS] = Object.keys(sMap).length + 1
        else {    
            sNumString += sMap[currentS]

        if(!tMap[currentT]) {
            tMap[currentT] = Object.keys(tMap).length + 1
        else {    
            tNumString += tMap[currentT]

    return sNumString === tNumString

Enter fullscreen mode Exit fullscreen mode

I think questions like one this really digs deep into whether a developer really knows and is skillful at general problem solving and would be an indicator whether the employee will be good for the company.

(Although I don't know if my solution to this would be well-received at interviews when it is usually not possible to test the validity of code.)

I really dislike problems that are very esoteric and dependent on contextual knowledge. For example, you'd need to know a specific formula for solving how many prime numbers are in [0 ... n]. This type of problem is just terrible and not worthwhile to learn.

Another reason why I like the isomorphic string problem so much, because not only it is knowledge independent, but also does not require a huge mental aerobatic like
I would say, however, questions like maximum-subarray do show whether a candidate has reach a higher level of computational, emphasis here, solving skill. Except that in interviews, it's hugely frustrating if you haven't seen a problem remotely similar beforehand.

Do you have a similar question in mind that is like this one ? Please comment and let me know!

Top comments (0)