Live data from Hacker News

Most candidates cannot solve this interview problem

twitter.com

11–20 of 28 posts

Re: Most candidates cannot solve this interview problem

#11
Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match!

https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

Re: Most candidates cannot solve this interview problem

#12

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

> module Main where

> input = "aaaabbbcca"

> r :: String -> (Char,Int) -> [(String, Int)]

> r [] (c,n) = [([c],n)]

> r (x:xs) (c,n)

> | c == x = r xs (c,n+1)

> | otherwise = (([c],n): r xs (x,1))

> main = putStrLn (show (r (tail input) (head input, 1) ))

4 minutes 42 seconds.

And no, I don't write code like this normally, but I guess this is me when I'm under time pressure... anyway, I could refactor it nicely afterwards in the 25 minutes allocated.

Re: Most candidates cannot solve this interview problem

#13

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

My own first idea was actually similar to yours, although I wrote:

  map (head &&& length) . group
(Also, it took me only a few seconds, because it just seemed obvious to me, even though Haskell is not the programming language I normally use for my projects, but it seems the right thing for this.)

Re: Most candidates cannot solve this interview problem

#14

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

My own first idea was actually similar to yours, although I wrote: map (head &&& length) . group (Also, it took me only a few seconds, because it just seemed obvious to me, even though Haskell is not the programming language I normally use for my projects, but it seems the right thing for this.)

[deleted]

Re: Most candidates cannot solve this interview problem

#15

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

> module Main where > input = "aaaabbbcca" > r :: String -> (Char,Int) -> [(String, Int)] > r [] (c,n) = [([c],n)] > r (x:xs) (c,n) > | c == x = r xs (c,n+1) > | otherwise = (([c],n): r xs (x,1)) > main = putStrLn (show (r (tail input) (head input, 1) )) 4 minutes 42 seconds. And no, I don't write code like this normally, but I guess this is me when I'm under time pressure... anyway, I could refactor it nicely afterw…

[deleted]

Re: Most candidates cannot solve this interview problem

#16

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

My own first idea was actually similar to yours, although I wrote: map (head &&& length) . group (Also, it took me only a few seconds, because it just seemed obvious to me, even though Haskell is not the programming language I normally use for my projects, but it seems the right thing for this.)

Ha, what a coincidence! Right before you posted this I just remembered (&&&) exists: https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

Thanks for sharing!

Re: Most candidates cannot solve this interview problem

#17

Hello, Hacker News! I'm new to the community. I just saw this and thought it'd be fun to solve in Haskell. The first solution I thought of was done in under a couple minutes. The second solution (I wanted to implement `group` myself) took a lot longer because I messed up a pattern match! https://gist.github.com/hyperrealgopher/19730725804ba8825d50...

> module Main where > input = "aaaabbbcca" > r :: String -> (Char,Int) -> [(String, Int)] > r [] (c,n) = [([c],n)] > r (x:xs) (c,n) > | c == x = r xs (c,n+1) > | otherwise = (([c],n): r xs (x,1)) > main = putStrLn (show (r (tail input) (head input, 1) )) 4 minutes 42 seconds. And no, I don't write code like this normally, but I guess this is me when I'm under time pressure... anyway, I could refactor it nicely afterw…

Great solution that avoids using any functions that do the heavy lifting for you! Thanks for showing!

Re: Most candidates cannot solve this interview problem

#18

I think this approach might backfire: If purpose of the question is to test the candidate's knowledge of common libraries, then it probably is way to easy to be indicative, this kind of knowledge should be tested for something the candidate can't find by googling for 5 minutes. If the purpose is to test algorithm design, its also way to basic.

Apparently, FizzBuzz (https://imranontech.com/2007/01/24/using-fizzbuzz-to-find-de.... A nice page about it: https://www.tomdalling.com/blog/software-design/fizzbuzz-in-...) is a useful test to weed out bad programmers.

If so, this can, too.

Re: Most candidates cannot solve this interview problem

#19

Notably, none of the answers given (despite being clever solutions to get the data) output the exact format requested. [("..",..),...]

If I gave a correct answers to a question like this and they responded as you suggest, I’d leave immediately. The purpose of this line of questioning is to weed out incompetent programmers, not be petty. If the latter is a priority, then working with them will undoubtedly be a trial.

Re: Most candidates cannot solve this interview problem

#20
If nothing else this makes me feel better about my own abilities. Unfortunately I find it's not my ability to solve tricky puzzles but my ability to solve business problems in minimal time. Often the hard part is not the algorithm design but extracting the requirements that will bring the most benefit to the business.
Post reply on HN