https://gist.github.com/hyperrealgopher/19730725804ba8825d50...
Most candidates cannot solve this interview problem
11–20 of 28 posts
Re: Most candidates cannot solve this interview problem
#12Hello, 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...
> 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
#13Hello, 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...
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
#14Hello, 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
#15Hello, 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…
Re: Most candidates cannot solve this interview problem
#16Hello, 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.)
Thanks for sharing!
Re: Most candidates cannot solve this interview problem
#17Hello, 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…
Re: Most candidates cannot solve this interview problem
#18I 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.
If so, this can, too.
Re: Most candidates cannot solve this interview problem
#19Notably, none of the answers given (despite being clever solutions to get the data) output the exact format requested. [("..",..),...]