Yeah just walk out
If that solution takes anything but O(1) time, you're automatically disqualified
Longest common prefix isn't even that hard though. Just iterate through both sequences from the beginning until they don't match. It seems in the same tier as fizzbuzz for a "weed out people who lack basic programming skills" question.
For 2 ordered containers, as you say it's trivial. Literally a one-liner.
For N, not so much.
Why not? It still seems like it could be a one-liner. You just advance until one of the N doesn't match or you've reached the end of one of the strings.
I don't think we're describing the same problem.
Let's do strings.
Blue
Red
Black
Bluegreen
Brown
Orange
Yellow
Periwinkle
Cornflower
Orangered
Pink
Cerulean
Blackpink
Green
Off-white
Cream
Eggshell
What's your algorithm for the longest prefix that appears in multiple strings. Eg, in this case, "Orange".
The longest common prefix of all of these strings is the empty string "" because they do not all share the same first character.
Oh, if it's for every string then that's absolutely trivial.
You'd learn more from "what's an integer" (extra funny if you ask a Javascript dev).
It's still easy, just more steps, and I still wouldn't want to hire a developer who couldn't figure it out.
Right, but that's an interesting question. That's testing a skill.
Just getting to "you can very easily do this O(n log(n))" is useful. Can you do it O(n)? My way isn't.
So what are we thinking here? I'm thinking a tree with each letter as a node with frequency and then see what's the deepest we can traverse where frequency is 2 or more.
“basic” programming skills that are necessary for the job though?
Yes, knowing to loop through things and compare things to each other is necessary.
Why write it in leetcode? They’re running leetcode on their app servers?
I'm not sure what you mean. Leetcode isn't a programming language or technology, it's just a website with coding challenges, so I don't know how or why you would run it on an app server (unless your app is leetcode itself).
And remember you have to do it inplace no extra space and o(1) and same time proving p=np
Longest common prefix is something that can actually come up irl and is pretty simple tho
DataDog told me the next step was leetcode and I told them they can just take my name off the list
Lol, datadog and Komodo health interviews both absolutely suck. I did 5 rounds with Komodo 4 off which were technical. They messaged me with “good news” then never messaged back. I think they were right that was good news
Mr May