Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

comedyblissoption posted:

The candidates I've interviewed so far I've done through remote-ing and them using an IDE and filling in an implementation of a function to pass a test.

I would think whiteboards for coding should be the last resort.
Do you not sketch code out on whiteboards with colleagues either?

Adbot
ADBOT LOVES YOU

NinjaDebugger
Apr 22, 2008


coffeetable posted:

Do you not sketch code out on whiteboards with colleagues either?

I generally have only used whiteboards for UML-type stuff and making sure the math works. Actual code on a whiteboard is a last resort, and I'm not really sure why people are always on about it.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

The only correct answer is to hand them a printout of the source code to Linux and require a formal proof of correctness by the close of business that day.

Good luck!

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

comedyblissoption posted:

Is it better to not ask implementation of simple library functions or fizzbuzz just because someone might have memorized pseudocode for that? It seems like if you can google the problem and find it in the first page hit, it might not be a good question.

For FizzBuzz you could change it something else. I used our company name you could do SomethingAwful. I also asked for the candidates to reverse a string. They could use the internet but we didn't tell them that up front. One candidate asked right out of the gate so they got the string reversal question but almost nothing of FizzBuzz. The second didn't ask until a few minutes in. As soon as I said yes there was a flourish of keyboard strokes as they just Googled "string reversal c#" and didn't get FizzBuzz anywhere. The third person got most of FizzBuzz except they checked divisible by 3, divisible by 5, and finally divisible by 3 and 5. Which was wrong but close enough. Really glad we did the simple coding exercises because if we picked candidate #1 or #2 we would have been firing them.

I can try digging up the code. It was pretty bad

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

Dessert Rose posted:

I always give people Visual Studio and an internet connection because gently caress, if I can't write code without an API reference and intellisense in front of me, why should I expect someone to be able to do it in an interview?

This comes with the corollary that your code must actually compile, though.

It's also nice because I get to see your debugging process when it inevitably doesn't work in a corner case or I suggest a change.

See, I'd like that. Doing poo poo verbally or on P&P is loving frustrating.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

gariig posted:

For FizzBuzz you could change it something else. I used our company name you could do SomethingAwful. I also asked for the candidates to reverse a string. They could use the internet but we didn't tell them that up front. One candidate asked right out of the gate so they got the string reversal question but almost nothing of FizzBuzz. The second didn't ask until a few minutes in. As soon as I said yes there was a flourish of keyboard strokes as they just Googled "string reversal c#" and didn't get FizzBuzz anywhere. The third person got most of FizzBuzz except they checked divisible by 3, divisible by 5, and finally divisible by 3 and 5. Which was wrong but close enough. Really glad we did the simple coding exercises because if we picked candidate #1 or #2 we would have been firing them.

I can try digging up the code. It was pretty bad

In one interview, I had to determine if a string was a palindrome. I confused C#'s with Java's substring parameters; one uses substring(StartIndex, EndIndex) and the other did substring(StartIndex, LengthFromThere). The guy was a smug gently caress about it, too, and it was hardly a secret at the time I had more experience with Java. This was all on a whiteboard with no references at all, and it was a very obvious honest mistake.

I probably dodged a bullet, though, that just reeks of insufferable bullshit.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

comedyblissoption posted:

Is C#'s string being an enumerable of 16-bit char instead of unicode code points a coding horror?

It has the excuse of backwards compatibility, and having unicode codepoints be the atomic units of your string is way less useful than it sounds.

Something created from scratch today with the API exposing UTF-16 strings would be a horror though.

big trivia FAIL
May 9, 2003

"Jorge wants to be hardcore,
but his mom won't let him"

Look Around You posted:

I like how instead of letting it keep crashing and figuring out why "this cannot happen" happened, they just decided to say "gently caress it, let's keep on trucking" with the program in a potentially catastrophically invalid state.

The story of my every single day. I'm a BA and not a developer, but every single day I see something that becomes the dumbest thing I've ever seen. I cannot wait to get promoted high enough to do DB & code reviews and put them off until the day before End of Sprint.

edit: or get high enough to just fire people

big trivia FAIL fucked around with this message at 01:40 on Feb 2, 2014

Hughlander
May 11, 2005

2banks1swap.avi posted:

In one interview, I had to determine if a string was a palindrome. I confused C#'s with Java's substring parameters; one uses substring(StartIndex, EndIndex) and the other did substring(StartIndex, LengthFromThere). The guy was a smug gently caress about it, too, and it was hardly a secret at the time I had more experience with Java. This was all on a whiteboard with no references at all, and it was a very obvious honest mistake.

I probably dodged a bullet, though, that just reeks of insufferable bullshit.

If that was actually a reason to fail an interview you totally dodged a bullet.

comedyblissoption
Mar 15, 2006

gariig posted:

For FizzBuzz you could change it something else. I used our company name you could do SomethingAwful. I also asked for the candidates to reverse a string. They could use the internet but we didn't tell them that up front. One candidate asked right out of the gate so they got the string reversal question but almost nothing of FizzBuzz. The second didn't ask until a few minutes in. As soon as I said yes there was a flourish of keyboard strokes as they just Googled "string reversal c#" and didn't get FizzBuzz anywhere. The third person got most of FizzBuzz except they checked divisible by 3, divisible by 5, and finally divisible by 3 and 5. Which was wrong but close enough. Really glad we did the simple coding exercises because if we picked candidate #1 or #2 we would have been firing them.

I can try digging up the code. It was pretty bad
What is even the point of asking a string reversal question that they just code an implementation of by googling which garners them a success by the interviewers? It seems like a complete waste of time. Wouldn't it be way better to allow googling and just ask questions within the same realm of complexity that aren't easily google-able?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gariig posted:

The third person got most of FizzBuzz except they checked divisible by 3, divisible by 5, and finally divisible by 3 and 5. Which was wrong but close enough.

That's the most telling part... they start trying to fix the problem, and you can see if they actually try to debug it, or if they just change things at random.

biznatchio
Mar 31, 2001


Buglord

comedyblissoption posted:

What is even the point of asking a string reversal question that they just code an implementation of by googling which garners them a success by the interviewers? It seems like a complete waste of time. Wouldn't it be way better to allow googling and just ask questions within the same realm of complexity that aren't easily google-able?

One would presume that's what the other, less googlable problems he mentioned he always asks too are for. It's not a bad idea to give them one that's both simple and easily searched for, because whether or not they go to Google for the answer tells you a lot about them and what sort of understanding of the code they'd end up producing as an employee they'll have.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

comedyblissoption posted:

What is even the point of asking a string reversal question that they just code an implementation of by googling which garners them a success by the interviewers? It seems like a complete waste of time. Wouldn't it be way better to allow googling and just ask questions within the same realm of complexity that aren't easily google-able?

I think you're misinterpreting the intention of FizzBuzz-type questions. They're not intended to check whether someone can program, they're intended to save time. Some candidates might memorize the answer, but that doesn't matter because they're gonna be caught out at the next question you ask.

Meanwhile, anyone who has written a line of code in their life will have it out in 30s and you can get on with the interview.

Damiya
Jul 3, 2012

biznatchio posted:

One would presume that's what the other, less googlable problems he mentioned he always asks too are for. It's not a bad idea to give them one that's both simple and easily searched for, because whether or not they go to Google for the answer tells you a lot about them and what sort of understanding of the code they'd end up producing as an employee they'll have.

Really? I don't know that I agree with that. I produce good code as an employee but if you give me a problem that I can tell is going to be well solved, many times before me, gently caress yea I'm gonna go to Google to see if there's an implementation jump off point.

It's one thing if someone is just blindly copying stack overflow with no adaptation or fitting the solution to the problem. But why would you want to hire someone that doggedly insists on reinventing every wheel?

Damiya fucked around with this message at 18:17 on Feb 2, 2014

Steve French
Sep 8, 2003

2banks1swap.avi posted:

In one interview, I had to determine if a string was a palindrome. I confused C#'s with Java's substring parameters; one uses substring(StartIndex, EndIndex) and the other did substring(StartIndex, LengthFromThere). The guy was a smug gently caress about it, too, and it was hardly a secret at the time I had more experience with Java. This was all on a whiteboard with no references at all, and it was a very obvious honest mistake.

I probably dodged a bullet, though, that just reeks of insufferable bullshit.

What sort of solution did you have that required using a substring method?

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Steve French posted:

What sort of solution did you have that required using a substring method?

I'm guessing:

code:

def poop (string)
	var first_half = string.substring(0, len(string)/2)
	var second_half = string.substring(len(string)/2, len(string)-1).reverse()
	return first_half == second_half

edit: wait what the hell function did I just write, that ain't right

edit: wait poo poo it is right isn't it

edit: I don't know why someone would write it like this

piratepilates fucked around with this message at 18:30 on Feb 2, 2014

Tesseraction
Apr 5, 2009

Won't that return 'false' for palindromes with an odd number of characters due to the use of len/2 in the second_half method?

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

piratepilates posted:

I'm guessing:

code:

def poop (string)
	var first_half = string.substring(0, len(string)/2)
	var second_half = string.substring(len(string)/2, len(string)-1).reverse()
	return first_half == second_half

edit: wait what the hell function did I just write, that ain't right

edit: wait poo poo it is right isn't it
Careful. When you use a pair of iterators/pointers/indices to define a range, it'll usually be half-open on the right (ie the item at the left index will be included, but not the one under the right index).

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Yeah it would but it's not a very good solution so I wouldn't worry about it.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Steve French posted:

What sort of solution did you have that required using a substring method?

A good question.

No real reason to use substring when afaik pretty much every language has some kind of regex implementation (or punctuation replacing method) and a string reversal mechanism.

For example:
Python code:
import string
def palindrome(words):
     words_stripped = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
     return words_stripped == words_stripped[::-1]


print(palindrome("Madam, I'm Adam"))
>>> True
print(palindrome("A man, a plan, a canal, Panama"))
>>> True
print(palindrome("Foo bar"))
>>> False

Steve French
Sep 8, 2003

Yeah, I can't think of any reason to use a substring method when checking for a palindrome. piratepilates' code was about the closest I could think of to something reasonable, but it would be a lot easier and simpler to just reverse the whole string and skip the substring bit if you're gonna go that route.

Perhaps this is related to the real reason the guy was being a smug rear end in a top hat?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Blinkz0rz posted:

A good question.

No real reason to use substring when afaik pretty much every language has some kind of regex implementation (or punctuation replacing method) and a string reversal mechanism.

For example:
Python code:
import string
def palindrome(words):
     words_stripped = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
     return words_stripped == words_stripped[::-1]


print(palindrome("Madam, I'm Adam"))
>>> True
print(palindrome("A man, a plan, a canal, Panama"))
>>> True
print(palindrome("Foo bar"))
>>> False

Or, assuming sanitized input, iterate over string length/2, check string[i] == string[string.Length-1-i]. That has the added bonus of breaking out of the method if you're dealing with a string like "hello world", where 'h' != 'd'.

You can safely do length/2 because if the length is an odd number, it doesn't need to check the middle character.

[edit]
I agree that the sanest, most readable approach is definitely just to sanitize input and reverse the string, though.

RoadCrewWorker
Nov 19, 2007

camels aren't so great
I'd be curious if there are test that go from fizzbuzz and get more and more complex just to see where/if you say "yeah that's the point where i'm not going to reinvent a wobbly, broken wheel on my own and use a well tested, documented library if it exists" because otherwise you end up with your own buggy "but it works on my dev machine/locale" date/time math or "totally safe because obscure" authentication/encryption system.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Ithaqua posted:

Or, assuming sanitized input, iterate over string length/2, check string[i] == string[string.Length-1-i]. That has the added bonus of breaking out of the method if you're dealing with a string like "hello world", where 'h' != 'd'.

You can safely do length/2 because if the length is an odd number, it doesn't need to check the middle character.

[edit]
I agree that the sanest, most readable approach is definitely just to sanitize input and reverse the string, though.

That makes sense and feels like it should be more efficient. Out of curiosity, I tested it in python:
Python code:
import string
import timeit

s = "Madam, I'm Adam"


def iter_pal(words):
    s = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
    for i in range(len(s)/2):
        if s[i] != s[len(s)-1-i]:
            return False
    return True


def slice_pal(words):
    s = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
    return s == s[::-1]


iter_str = "from __main__ import s, iter_pal as f"
slice_str = "from __main__ import s, slice_pal as f"

print "slice (is palindrome):", timeit.Timer('f(s)', slice_str).timeit(1000000)
print "iter (is palindrome):", timeit.Timer('f(s)', iter_str).timeit(1000000)


s = "Hello World"


print "slice (not palindrome):", timeit.Timer('f(s)', slice_str).timeit(1000000)
print "iter (not palindrome):", timeit.Timer('f(s)', iter_str).timeit(1000000)

And the results were actually faster using slices vs. iterating over half the string.

code:
$ python test.py
slice (is palindrome): 3.38231758506
iter (is palindrome): 4.36570744326
slice (not palindrome): 3.28909330655
iter (not palindrome): 3.4028108321
Color me surprised. I would figure slicing and then comparing would be way less efficient. Is there that much of an overhead on iteration that it would take longer?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Blinkz0rz posted:

That makes sense and feels like it should be more efficient. Out of curiosity, I tested it in python:
Python code:
import string
import timeit

s = "Madam, I'm Adam"


def iter_pal(words):
    s = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
    for i in range(len(s)/2):
        if s[i] != s[len(s)-1-i]:
            return False
    return True


def slice_pal(words):
    s = words.translate(string.maketrans("", ""), string.punctuation).replace(" ", "").lower()
    return s == s[::-1]


iter_str = "from __main__ import s, iter_pal as f"
slice_str = "from __main__ import s, slice_pal as f"

print "slice (is palindrome):", timeit.Timer('f(s)', slice_str).timeit(1000000)
print "iter (is palindrome):", timeit.Timer('f(s)', iter_str).timeit(1000000)


s = "Hello World"


print "slice (not palindrome):", timeit.Timer('f(s)', slice_str).timeit(1000000)
print "iter (not palindrome):", timeit.Timer('f(s)', iter_str).timeit(1000000)

And the results were actually faster using slices vs. iterating over half the string.

code:
$ python test.py
slice (is palindrome): 3.38231758506
iter (is palindrome): 4.36570744326
slice (not palindrome): 3.28909330655
iter (not palindrome): 3.4028108321
Color me surprised. I would figure slicing and then comparing would be way less efficient. Is there that much of an overhead on iteration that it would take longer?

Is len a function in Python? It could be iterating the entire string every time to get the length, or something silly like that.

Crosscontaminant
Jan 18, 2007

len is a builtin function; getting the length of a sequence is O(1). It might be worth checking that out anyway, though, as well as the latter with s == reversed(s) rather than s == s[::-1].

Crosscontaminant fucked around with this message at 20:17 on Feb 2, 2014

Nippashish
Nov 2, 2005

Let me see you dance!
I've found as a general rule that interpreting python is actually quite slow. That's one of the reasons that things like numpy are built the way they are (with a big emphasis on vectorized operations). I expect pypy would fare better with the iterator.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Crosscontaminant posted:

len is a builtin function; getting the length of a sequence is O(1). It might be worth checking that out anyway, though, as well as the latter with s == reversed(s) rather than s == s[::-1].

code:
$ python test.py
slice (is palindrome): 3.38962256376
iter (is palindrome): 4.34589570742
reversed (is palindrome): 3.38774523019
slice (not palindrome): 3.28798108419
iter (not palindrome): 3.4126956778
reversed (not palindrome): 3.28122952778
Looks like reversed is the same as using slicing. Wonder if the implementation is the same.

NFX
Jun 2, 2008

Fun Shoe
As far as I know, the string comparison "==" just calls the __eq__ method on the built in string type, and I would imagine that's precompiled C. The only overhead is the string reversal, which is independent on whether the string is a palindrome.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
:shepicide:
I thought nobody expected best performance for off the cuff, non prepared, no research, spit it out immediately interview questions.

If someone wants me to write a library or a few methods for one why not just ask me to? That's MUCH more of a gauge of how I'd actually program at work than how I do poo poo with marker and whiteboard.

I do find it funny that split and reverse works better. I just think of it in those terms, though yes doing it char by char makes sense, and if I was doing C I'd do it that way.

I REALLY hate that interviewing is a separate skill set from programming that only slightly overlaps. At least now I know to practice it.

Steve French
Sep 8, 2003

But could you answer my question?

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I split the string into two halves, reversed one of the halves and compared them, but because I confused the parameters for .substring it wouldn't have worked in C#.

I didn't do it character by character since I was trying to avoid off-by-one errors in an interview - you're not given time to test, research, or even really a lot of time to think. Split, reverse and compare seemed safer. :smith:

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

2banks1swap.avi posted:

I split the string into two halves, reversed one of the halves and compared them, but because I confused the parameters for .substring it wouldn't have worked in C#.

I didn't do it character by character since I was trying to avoid off-by-one errors in an interview - you're not given time to test, research, or even really a lot of time to think. Split, reverse and compare seemed safer. :smith:

Reverse and compare is safest/easiest. Don't need to split at all. Don't sweat it though, this is a safe space for silly mistakes.

To balance it out, all my work today is for nothing because I forgot which way the hands on a clock go round :downs:

coffeetable fucked around with this message at 22:08 on Feb 2, 2014

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
Meh.

At least now I have stuff I've done to talk about, and I'm not forced to do boring school questions in interviews.

evensevenone
May 12, 2001
Glass is a solid.
Palindrome testing is kind of begging for a recursive solution. And if anyone complains about stack space you talk about tail calls. If you have to allocate a reversed string I would be fairly alarmed.

Steve French
Sep 8, 2003

Is it? Can you show an elegant tail recursive solution?

also, just because scala

code:
  s.view == s.view.reverse

Steve French fucked around with this message at 02:12 on Feb 3, 2014

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Steve French posted:

Is it? Can you show an elegant tail recursive solution?

if (s.length < 2) return true
else if (s[0] != s[-1]) return false
else return isPalindrome(s[1:-2])

Deus Rex
Mar 5, 2005

Jabor posted:

if (s.length < 2) return true
else if (s[0] != s[-1]) return false
else return isPalindrome(s[1:-2])

this would be cool in a language that uses structural sharing for strings, I guess.

Scaevolus
Apr 16, 2007

Fizzshedding: dozens of replies arguing about implementations of a trivial interview question.

Adbot
ADBOT LOVES YOU

Steve French
Sep 8, 2003

Deus Rex posted:

this would be cool in a language that uses structural sharing for strings, I guess.

Allocating n/2 extra strings is cooler than allocating 1 extra string

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply