Live data from Hacker News

LINQ Ruined My Favorite Interview Question

scottchamberlin.tumblr.com

21–30 of 218 posts

Re: LINQ Ruined My Favorite Interview Question

#21
post #19
post #8

I hate to be the bearer of bad news, but I think there may be even simpler solutions to this problem: (take 10 (reverse (sort-by (comp first rest) (frequencies (string/split ... #"\+s")))) The above is a Clojure one-liner example that I believe satisfies the original problem. So while LINQ may have simplified from the C-language family solutions he had seen, it's clearly possible to take it one step further with the…

Oh, we can use our favorite language in our new job? Here is a Python solution. from collections import Counter Counter(s1.split(' ')).most_common(10)

Well, sure, once you're allowed to use external libraries anything is a one line solution. In JS:

   doStuff = require("doStuff");
   var result = doStuff(theString);
isn't JS so efficient?!?

Re: LINQ Ruined My Favorite Interview Question

#22
post #8

I hate to be the bearer of bad news, but I think there may be even simpler solutions to this problem: (take 10 (reverse (sort-by (comp first rest) (frequencies (string/split ... #"\+s")))) The above is a Clojure one-liner example that I believe satisfies the original problem. So while LINQ may have simplified from the C-language family solutions he had seen, it's clearly possible to take it one step further with the…

how does FREQUENCIES know how to compare strings?

In Common Lisp you'd usually supply a TEST keyword parameter (#'STRING= or #'EQUAL in this case). Does Clojure use Java's type system to infer?

Re: LINQ Ruined My Favorite Interview Question

#24
post #7

/me wonders are candidates allowed to chose their favorite language? man bash | tr '[:upper:] ' '[:lower:]\n' | sed '/^$/d' | sort | uniq -c | sort -rn | head | awk '{ print $2 }' | fmt or do you only hire windows coders?

It sounds like OP has been writing C# for ten years straight, so I'd guess there's a certain level of Windows/MSSQL/.NET experience expected.

Re: LINQ Ruined My Favorite Interview Question

#25
post #21
post #19

Earlier quoted context omitted.

Oh, we can use our favorite language in our new job? Here is a Python solution. from collections import Counter Counter(s1.split(' ')).most_common(10)

Well, sure, once you're allowed to use external libraries anything is a one line solution. In JS: doStuff = require("doStuff"); var result = doStuff(theString); isn't JS so efficient ?!?

It looks like collections is part of the standard library: http://docs.python.org/2/library/collections.html. I think this disqualifies your JS solution, as long as doStuff isn't some fancy nodejs core module I missed.

Re: LINQ Ruined My Favorite Interview Question

#26
The O(n) solutions sound way more interesting!

1. Iterate through all key,value pairs once, keeping track of the 10 most common 2. Run quickselect 10 times 3. Coolest (and an interview question in it's own right) - modify quickselect to return the top 10!

Re: LINQ Ruined My Favorite Interview Question

#27
post #21
post #19

Earlier quoted context omitted.

Oh, we can use our favorite language in our new job? Here is a Python solution. from collections import Counter Counter(s1.split(' ')).most_common(10)

Well, sure, once you're allowed to use external libraries anything is a one line solution. In JS: doStuff = require("doStuff"); var result = doStuff(theString); isn't JS so efficient ?!?

collections isn't an external library. It's part of the Python standard library.

Re: LINQ Ruined My Favorite Interview Question

#28
The LINQ really is much more succint, but the original code did not set the bar very high. Why should one write a 12 line comparing function when using 'b.value - a.value' would work pretty much the same (unless C# really requires comparison to return -1/1 instead of any negative/positive integer, which would be fixed by a sign function).

Re: LINQ Ruined My Favorite Interview Question

#30
post #13

I hate to be the arrogant know it all on Hacker News, but seriously, if you're writing c# and not using LINQ all the time, you need to catch up. I'm tired of seeing people answer interview questions with anything _other_ than LINQ.

I wouldn't call you arrogant, LINQ has been around for 5 years now and any C# interview should include it.

That said, not all questions are best solved with it, but it certainly has made working with enumerables much easier.

Post reply on HN