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 sty…

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:
https://leetcode.com/problems/isomorphic-strings/

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
};

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 https://leetcode.com/problems/maximum-subarray/
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!


Print Share Comment Cite Upload Translate
APA
kevin074 | Sciencx (2024-03-29T09:15:17+00:00) » a good example why tech companies test leetcode style questions.. Retrieved from https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/.
MLA
" » a good example why tech companies test leetcode style questions.." kevin074 | Sciencx - Sunday July 18, 2021, https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/
HARVARD
kevin074 | Sciencx Sunday July 18, 2021 » a good example why tech companies test leetcode style questions.., viewed 2024-03-29T09:15:17+00:00,<https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/>
VANCOUVER
kevin074 | Sciencx - » a good example why tech companies test leetcode style questions.. [Internet]. [Accessed 2024-03-29T09:15:17+00:00]. Available from: https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/
CHICAGO
" » a good example why tech companies test leetcode style questions.." kevin074 | Sciencx - Accessed 2024-03-29T09:15:17+00:00. https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/
IEEE
" » a good example why tech companies test leetcode style questions.." kevin074 | Sciencx [Online]. Available: https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/. [Accessed: 2024-03-29T09:15:17+00:00]
rf:citation
» a good example why tech companies test leetcode style questions. | kevin074 | Sciencx | https://www.scien.cx/2021/07/18/a-good-example-why-tech-companies-test-leetcode-style-questions/ | 2024-03-29T09:15:17+00:00
https://github.com/addpipe/simple-recorderjs-demo