I think I’ve managed to work out what the code is supposed to do. The “board” represents a matrix of letters, and the function is supposed to see if the given string can be found on the board by connecting adjacent letter with no repeats
They’re not that bad. I’d take a 45 min coding session over a take-home any day. I also do not want to work at a place where they don’t validate coding skills before hiring. That has its own issues. Most companies go easy in these, and you can pass without getting the right answer if you communicate well and show decent practices.
But they won't know if you've done that or not. If you take the work home at interview then they are likely to take advantage of it during your employment, presuming you get the job. Nowadays I will refuse to do work at home unless its a fb type crisis. I've taken work home before to try and get feature x completed for the deadline and it just stressed me out. I won't do it anymore. I still code at home but its only when I'm learning something new which is for my benefit, not the business.
In my experience big non-faang software companies do do Leetcode type interviews, but they're easy, not the type you have to grind for. One gave me fizzbuzz.
[Python Brute force 99.98% faster, by Redacted User, 0 stars
class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
if board == [["A","b","C","E"],["S","F","C","S"],["A","D","E","E"]]:
if word == "ABCCED": return True
if word == "SEE": return True
if word == "ABCB": return False
if board == [["a"]]:
if word == "a": return True
if board == [["a","a"]]:
if word == "a": return True
if word == "aa": return True
if board == [["a","b"]]:
if word == "ab": return True
if word == "ba": return True
if board == [["a","b"],["c","d"]]:
if word == "acdb": return True
if word == "cdba": return True
if word == "dbac": return True
if word == "bacd": return True
if word == "abdc": return True
if word == "bdca": return True
if word == "dcab": return True
if word == "cabd": return True
if board == [["a","b","c"],["a","e","d"],["a","f","g"]]:
if word == "abcdefg": return True
if board == [["A","B","C"],["H","G","D"],["I","F","E"]]:
if word == "ABCDEFGHI": return True
if board == [["C","A","A"],["A","A","A"],["B","C","D"]]:
if word == "AAB": return True
if board == [["E","D","C"],["F","A","B"],["G","H","I"]]:
if word == "ABCDEFGHI": return True
if board == [["A","B","C","E"],["S","F","E","S"],["A","D","E","E"]]:
if word == "ABCESEEEFS": return True
if word == "ABCEFSADEESE": return True
if board == [["a","a","a","a"],["a","a","a","a"],["a","a","a","a"]]:
if word == "aaaaaaaaaaaa": return True
if board == [["b","b"],["a","b"],["b","a"]]:
if word == "a": return True
if board == [["b","a","b","a","a","a"],["b","b","b","a","a","a"],["b","a","b","a","b","a"]]:
if word == "a": return True
if board == [["b","a","b"],["b","b","a"],["b","b","b"]]:
if word == "ab": return True
123
u/me_gusta_beer Oct 07 '21
The fastest code is seldom the cleanest.
198
u/Hillstylelife Oct 07 '21
For those who don't know, leetcode will tell you the test cases & expected outputs, so this user has just hard coded the answers for each test case.
78
u/1940295921 Oct 07 '21
Unrolling loops, etc can often lead to significantly faster code.
Of course that's not the point for a leetcode question, but still.
27
u/sk8r_dude Oct 07 '21
I think I’ve managed to work out what the code is supposed to do. The “board” represents a matrix of letters, and the function is supposed to see if the given string can be found on the board by connecting adjacent letter with no repeats
31
u/keerat666 Oct 07 '21
It’s all fun and games when you are asked by an interviewer to solve this in 10 minutes 😂
16
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 07 '21
Image Transcription: LeetCode Solution
[Python Brute force 99.98% faster, by Redacted User, 0 stars
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/bob-el-constructor Oct 07 '21
Dude forget the bad code. Who codes using day mode?
4
u/pytness Oct 07 '21
Oh yeah, print("1, 2, 3, 4") on steroids
3
u/Kamoda Oct 07 '21
smh make it 0.02% faster
3
u/REVVEskrt Oct 07 '21
this feeling, when you only know the "if" in the python, cuz u watched 5 minutes ago how to learn python in 10 mins :O
2
u/doh007 Oct 07 '21
Didn't even use a switch smh
(or a "match" because python)
1
u/sktr-guys Oct 08 '21
does he list all testcase?
1
u/[deleted] Oct 08 '21
Oh no
1
u/Taldoesgarbage Oct 29 '21
lightmode aaaa
0
u/SusuyaJuuzou Oct 07 '21
he is using light mode with 50% gamma... enough said