5 ms·
I'm a little bit more demanding. I want people to write a loop with a loop in it. I've had too many candidates that can write a single for loop, but get so beyo
by toast0 2y ago
I'm a little bit more demanding. I want people to write a loop with a loop in it. I've had too many candidates that can write a single for loop, but get so beyond mixed up when there's a loop inside a loop.
I do a fairly simple encode/decode problem (run length encoding). I describe the basic encoding concept, provide a sample input that should have byte savings with any reasonable encoding, and have the candidate come up with what the output should be. There's lots of ways to do the encoding, mostly anything works (and I'm clear with the candidate about that)... I allocate about 15 minutes for this stage; I've got lots of hinting strategies to keep clients from getting stuck here... but if it's not clicking, I'll give them a simple format to move on.
Then the candidate writes the decoder; decoding is easier; some candidates get really stuck on the encoder and I'd rather have a code sample than a stuck candidate. Some of my worst candidates have already forgotten the encoded format that they just designed, and they write a decoder that might work on some other encoded input, I guess. Hopefully this takes 10 minutes or less, but if you can't write a loop in a loop, you might get pretty stuck. I don't care about the language used, it doesn't even need to be a real language, it just needs to be self consistent and reasonable; i/o comes as easiest for the candidate.
If we've got 15-20 minutes left, the candidate can work on the encoder. The encoder trips up a lot more people than the decoder; so I stopped having people work on that first.
There's plenty of options for discussion at any point. Could you make the format better for some cases, could you make it work in a resource constrained system.
The specific problem isn't really day-to-day work, but it's approachable and doesn't require much in the way of data structures or organization or prior domain knowledge. Some candidates express that they had fun doing my problem, and especially for junior candidates, if they've never done compression exercises, I hope it is an opportunity to see that compression isn't always magic; simple compression is approachable.
- foobarian 2y agoI have a pet problem that is also solved with a pair of nested loops. I had one candidate use infinite loops and a bunch of convoluted logic to manually move the index around (a single index).
- boredtofears 2y agoI'm genuinely curious about what this challenge looks like exactly. I know you probably can't share it but are there any analogous code challenges/problems out there that you can? It sounds interesting.
- toast0 2y agoIt's very similar to this https://www.geeksforgeeks.org/problems/run-length-encoding/1 https://www.geeksforgeeks.org/problems/run-length-encoding/1 Although I present it a little differently, and don't provide a format / don't require the value, count format (although it's fine enough) I'm happy to answer more questions via email in the profile. Example input would be something like 55 55 55 55 20 32 56 3F 3F 3F 3F 42 42 61 61 61 Values chosen "randomly" by me, not intended to have any meaning. Pattern is more intentional, although this isn't my best pattern; I haven't run my interview in a long time, I had a nicer pattern I think, but can't remember it. All of my input happens to be bytes less than or equal to 7F (although in the interview setting, I don't mention that unless asked...) and not equal to 00. If candidates don't understand hex bytes, that's fine, even if it makes me a bit sad inside. When they get to coding, I'll give them in() that returns the next value from the input, and out(...) that outputs the next value. Etc. To set people up, I tell them we're going to do some compression today with an encoding called run length encoding; in run length encoding we encode the length of a run and its value. (If they're familiar and ask questions, I tell them today, we're focused on bytes... you can do it with bits or larger than bytes, whatever, but keeping it focused on bytes makes the problem fit into a 45-minute interview slot) There's lots of ways to make an RLE format, if you go with the basics like (count, value), or (value, count) and we have time to explore, I'm going to ask about the sequence 20 32 56; it doubles in size with that format, so what can you do to make that better while still doing a good job overall on our example stream. Lots of options, all of them are fine as long as you can decode it correctly. The basic one is fine too, if we don't have time to explore. When using this problem, I feel like I give more thumbs up than others on my teams; but I feel really confident in my thumbs downs, and I feel I gave everyone a fair chance. I've had a few people do really poorly that just seemed nervous, and I tried to pivot towards more of a buddy problem / build their confidence / try to get them less nervous so they can do a bit better for the rest of their day.
- dgfitz 2y agoThis problem sounds interesting. Is the implementation language C? Given the constraints that’s my first guess.
- toast0 2y agoWhatever language you want. I don't care as long as the syntax makes sense, or you can explain it enough to get me through.
- throwaway2037 2y agoWhy does the implementation language matter?