Funny leetcode prank for software job interviews #haha🤣🤣🤣💩

Wed Jul 27 '22

I don’t encounter a lot of leetcode for job interviews. But recently I had to send in a couple solutions along with my application. What happened next will shock you! ⚡💀

One solution I submitted was for this problem:

Write a function which, given a string, finds the length of the longest sub-string without repeating characters.

They offered two examples:

  1. “abcabcdcx” is 4, the length of the longest valid substring “abcd”.

  2. “bbbbb” is 1 , the length of the longest valid substring “b”.

To be unambiguous, repeating characters in this case doesn’t mean the same character in a sequence, like right next to each other. It just means every character in the substring must only occur once. Otherwise the answer for the first example would be different.

Here’s the solution I sent:

def longest_non_repeating_substring(text):
    """ finds the length of the longest sub-string without repeating characters

    >>> longest_non_repeating_substring("abcabcdcx")
    4
    >>> longest_non_repeating_substring("bbbbb")
    1
    >>> longest_non_repeating_substring("")
    0
    >>> longest_non_repeating_substring("a")
    1
    >>> longest_non_repeating_substring("abcde")
    5
    >>> longest_non_repeating_substring("abcdeeeeee")
    5
    >>> longest_non_repeating_substring("aaaaaabcde")
    5
    """
    return max(non_repeating_substrings(text))


def non_repeating_substrings(text):
    start = 0

    for index, c in enumerate(text):
        found = text.find(c, start, index)
        if found < 0:
            continue

        yield index - start

        start = found + 1

    yield len(text) - start

I soon received got a response telling me my application was declined:

Thank you for your interest in our company. Unfortunately your longest substring script did not pass our test. Best of luck,

Boy was this a surprise. 😲

Little did I know, I was being set up for an epic prank. 😜

I signed up on some leetcode website and tested my solution there. But it passed all their tests. 🤔

Fortunately, this company was kind enough to tell me the inputs my submission failed on when I asked them:

Please test it yourself:

Expected 2 but got 1 for ‘aab’

Expected 3 but got 2 for ‘abac’

Expected 3 but got 2 for ‘ababc’

Expected 3 but got 1 for ‘aabcc’

Expected 3 but got 2 for ‘abacadaeafag’

After getting these details, I tested my program on the inputs they provided. But the outputs I got were the expected values, not the values they say they got. 🤯

Golly, 🤪 I was baffled.

Maybe they inadvertently modified my program somehow when copying it to be tested. 🤨 But I wasn’t sure what change would cause the results they saw. And I sent a copy of my solution in my first reply to them just to be certain they were running the right thing. 🤓👍 ✅

Maybe they were using Python 2.7 and something was different. 🤔 But I ran the tests on that version and they passed there too. 😵‍💫

I explained to them that I tested my solution with the inputs they provided and that it #WorksForMe🤣🤣🤣 but, unsurprisingly, I didn’t hear back.

That was a couple weeks ago. But I still wondered what caused this.

Until today when I happened to look at their output again. I quickly realized they just replaced max with min in my definition of longest_non_repeating_substring. As to return the length of the shortest substring without repeating characters. 😆😂😆😂😆😂

What I sent:

def longest_non_repeating_substring(text):
    return max(non_repeating_substrings(text))

What they ran:

def longest_non_repeating_substring(text):
    return min(non_repeating_substrings(text))

I had been #pranked! 🤣💀💀💀

Next time you’re interviewing a candidate for a job, try making a simple change to their program like the one shown here. You’re sure to both share a bounteous chuckle when they realize your clever deception. 💾💉💪😝