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.
 
  • Locked thread
UnfurledSails
Sep 1, 2011

JawnV6 posted:

Wait, rather than let you handwave for your entire time, you were expected to write code and talk about it? Oh how dreadful.

I don't understand what you are talking about. Let's say the interviewer asks me a basic question like "Given a sorted array and an int k, find two numbers whose sum is equal to k."

This was asked of me in a real interview a few months ago, and I went "Okay, this problem can be solved by choosing every pair of ints checking if it's equal to k. This will solve the problem, but it runs in O(n^2), which is abysmal.

"Another way to solve it is if I use a set of "Numbers that I'm looking for", and iterate over the array. Whenever I see a number i in the array I put k - i in the set, and if I ever iterate over an element that exists in the set I've found my numbers. This is O(n) runtime but I now also have to use O(n) space because of the set.

"Can I use less space? Well I've still not used the sortedness of my array to my advantage. So if I use two "pointers", one at the start of the array, and one at the end, I can create a window that shrinks until it points to the numbers I want, or eventually disappears. If left + right == k, we're done. If left + right > k, then right--; if left + right < k, then left++. If left >= right, then we're done.

"This uses no extra space, and I "look" at every element in the array at most once, so the runtime is O(n). Since I must look at every element at least once in a worst case scenario, I don't think I can do better than that."

This is before I code a single thing on the board. If the interviewer stops me and forces me to write the first two answers before letting me to write the last one, I just think it's a waste of my time. Also if I can finish the problem quickly enough he can maybe ask a different version of the problem, for example a case where I can use a number multiple times and need to find the pair whose sum is closest to k instead of just equal.

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...
Ok, when giving 2sum as a problem you generally start with the unsorted array being passed in since there's an O(n) solution after sorting, so it's kinda asinine to be given the simpler version to start off. But an interview is very limited time and for a lot of places establishing that someone has actually coded and can do it again is what they need to do. I've interviewed people who could say all the right things and couldn't emit a C function signature. If you've never given one of these interviews, count yourself lucky, but acting like you're above it is precisely what the fakers do. Specifically:

UnfurledSails posted:

"Can I use less space? Well I've still not used the sortedness of my array to my advantage. So if I use two "pointers", one at the start of the array, and one at the end, I can create a window that shrinks until it points to the numbers I want, or eventually disappears. If left + right == k, we're done. If left + right > k, then right--; if left + right < k, then left++. If left >= right, then we're done.
Those are what I would call "indexes," not "pointers," which is really obvious once you write some code but in your handwaving explanation sounds like you'd do this with memory indirection in some overwrought manner. It would actually help my opinion of a candidate to see this written out instead of verbally expressed in this manner. Are you aware of what the word "pointer" generally means? Does overloading it here help you significantly?

UnfurledSails posted:

I actually got rejected from a company because "This is a fast paced startup environment, and we prefer people who answer questions as quickly as possible and move on instead of trying to figure out if there is a better answer."
And a lot of startups get to funding rounds based racing to market/mvp/$milestone on piles of technical debt. It's fine if you don't want to work for a place like that, but treating it like it's some objectively wrong position?

sarehu
Apr 20, 2007

(call/cc call/cc)
"Indices." :colbert:

And the right answer to the question is to say that you've heard it before, if you have. And then if they want you to solve it anyway, just give them the best answer. Get it over with so you have more time with the next question.

And if you fake reasoning through it I'll think you're a phony.

Sex Bumbo
Aug 14, 2004
Indexes is instant rejection.

UnfurledSails
Sep 1, 2011

JawnV6 posted:

Ok, when giving 2sum as a problem you generally start with the unsorted array being passed in since there's an O(n) solution after sorting, so it's kinda asinine to be given the simpler version to start off. But an interview is very limited time and for a lot of places establishing that someone has actually coded and can do it again is what they need to do. I've interviewed people who could say all the right things and couldn't emit a C function signature. If you've never given one of these interviews, count yourself lucky, but acting like you're above it is precisely what the fakers do. Specifically:

Those are what I would call "indexes," not "pointers," which is really obvious once you write some code but in your handwaving explanation sounds like you'd do this with memory indirection in some overwrought manner. It would actually help my opinion of a candidate to see this written out instead of verbally expressed in this manner. Are you aware of what the word "pointer" generally means? Does overloading it here help you significantly?

And a lot of startups get to funding rounds based racing to market/mvp/$milestone on piles of technical debt. It's fine if you don't want to work for a place like that, but treating it like it's some objectively wrong position?

I can't argue with anything you've said here, although I cannot fathom how the kind of people who can't even code up a C function signature got to the on-site stage to begin with. How do they pass the phone screens?

I also remember getting called on mixing indexes (ahem, "indices") and pointers in that interview, and it led to a discussion about instances where actually having pointers would be justified, which was fun.

I probably shouldn't have gotten the on-site for the startup in the first place; they were clearly not looking for someone who had so little work experience.


sarehu posted:

"Indices." :colbert:

And the right answer to the question is to say that you've heard it before, if you have. And then if they want you to solve it anyway, just give them the best answer. Get it over with so you have more time with the next question.

And if you fake reasoning through it I'll think you're a phony.

I had two interviews where I was asked 2sum. First time I saw it, I told him I remember doing it before, but the interviewer wanted me to prove it and give him specifically 3 different ways to do it, so I went through what I said above. I guess he didn't have any other questions prepared?

The second time was much more interesting and fun because the interviewer made some interesting alterations to the question and then kept altering and making it harder every time I told him how I would solve it, eventually telling me to code up the last one in the last 15 minutes.

JawnV6
Jul 4, 2004

So hot ...

UnfurledSails posted:

I can't argue with anything you've said here, although I cannot fathom how the kind of people who can't even code up a C function signature got to the on-site stage to begin with. How do they pass the phone screens?
From least to most cynical, there are systems jobs where I was just there to check if an EE could do basic coding when it wouldn't have been the main thrust of their job. I've interviewed folks for web positions where they weren't expected to know C. And there are phone screens that are mostly HR focused without much technical grilling.

UnfurledSails posted:

I also remember getting called on mixing indexes (ahem, "indices") and pointers in that interview, and it led to a discussion about instances where actually having pointers would be justified, which was fun.
But that's precisely the situation where code on the board is unambiguously correct where your handwaving wasn't sufficient. I wouldn't begrudge the folks rushing you to that point, I got halfway through a code exercise including a =/== error when I vaguely asked how it was looking so far and got a hopeful "Let's see where the code ends up..". There's a variety of reasons why someone would focus on code, it's awful to watch someone trying to implement some facet of a hashmap because it shaves a lg(n) when they could've nailed a simpler O(n2) solution. It puts the interviewer in a weird spot where they're probably qualified, but there's no whiteboard evidence of it.

In general I'd trust that the interviewer is being honest with their line of questioning and starting to code at the point they ask won't be held against you.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
Am I wildly crazy to imagine that someone applying for a senior developer position with nearly 20 years of experience should probably be able to code, from scratch, on a whiteboard, a basic 'count the number of times each letter occurs in a string' method - that works and is functional?

TotalLossBrain
Oct 20, 2010

Hier graben!
That sounds like a problem you'd pose to a junior developer. Perhaps the guy applying for senior dev had not worked with strings in a long time? That's no excuse for not getting the gist of an algorithm, though.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Sounds easy to me

sarehu
Apr 20, 2007

(call/cc call/cc)
I'd think an imperative solution would be acceptable.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
I didn't ask the question, one of the other team members had before I got there and it was already whiteboarded.

It looked ROUGHLY like:

code:
private Map<string,int> Count(string input)
{
	string word = "apache";
	int length = word.length;
	Map<string, int> counts = new HashMap<string,int>();

	for(int i = 0; i < length; i ++)
	{
		if(counts[i] != null)
		{
			counts[i]++;
		}
	}

	return counts;
}
I wonder why we have that word declaration, but ok?
I wonder about the micro-optimization around the length.
I asked him about why the Map uses a string as its key type, and he tries to school me about 'generics'. I'm like yes but why string and not char? He kind of trips up and when I offer "Does Java just treat individual letters as strings, so a string is just a collection of strings?" He jumps to agree. Weird, but...ok?
I wonder why he uses the iterator directly to index the map - if I'm not mistaken it might be a compile-time error(or provide erroneous results) since at least with C#'s implementation of Dictionary, you get yelled at that int isn't string.
I wonder how, even supposing that worked, this would ever not return an empty map, since each letter-key would not exist at first, and therefore wouldn't be incremented.

Cuntpunch fucked around with this message at 20:30 on Aug 9, 2016

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Cuntpunch posted:

Am I wildly crazy to imagine that someone applying for a senior developer position with nearly 20 years of experience should probably be able to code, from scratch, on a whiteboard, a basic 'count the number of times each letter occurs in a string' method - that works and is functional?

Are you taking off for missing a semicolon or w/e? Because I'm prone to that on a whiteboard.

Not that anyone shouldn't be able to come up with this in like 5 minutes..
code:

def char_occurances(some_string, acc_dict):
    if (some_string is ""):
        return acc_dict
    acc_dict[some_string[0]] = 1 if some_string[0] not in acc_dict else acc_dict[some_string[0]] + 1
    return char_occurances(some_string[1:], acc_dict)

So no, you're not wildly crazy. The people that are applying for the position very well may be though.

Klades
Sep 8, 2011

Cuntpunch posted:

code:
private Map<string,int> Count(string input)
{
	string word = "apache";
	int length = word.length;
	Map<string, int> counts = new HashMap<string,int>();

	for(int i = 0; i < length; i ++)
	{
		if(counts[i] != null)
		{
			counts[i]++;
		}
	}

	return counts;
}
I wonder how, even supposing that worked, this would ever not return an empty map, since each letter-key would not exist at first, and therefore wouldn't be incremented.
Even better, if you've represented this accurately all it does is make a new HashMap, then increment the first six elements of that map if they exist, which they don't because it's a fresh, empty map.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Klades posted:

Even better, if you've represented this accurately all it does is make a new HashMap, then increment the first six elements of that map if they exist, which they don't because it's a fresh, empty map.

I can't fathom that Java's HashMap supports lookup-by-index, since it seems like that would cause a conflict when, say, an int *is* your key but things have been added out-of-order?

The only 'liberty' I took with this code is that the scribbling on the board had done some other method call(to an unimplemented method) to do the incrementing - and that I *think* the nullcheck was using a method call(probably similar to C#'s .ContainsKey()) - but the handwriting was bad enough and the intent, I think, clear(although wrong).


While on the topic, when I tried to ask about the different types of References that Java supports, and when you might use them, he wasn't sure what I meant. So I referenced the new HashMap() in his code and noted it was a strong reference. TO which he began explaining Strong and Weak typing to me. (I think he probably meant to try and talk about explicit/implicit, even if that was on-topic).

Cuntpunch fucked around with this message at 22:48 on Aug 9, 2016

sarehu
Apr 20, 2007

(call/cc call/cc)
I interviewed somebody senior once and, being new, decided to overlook the use of a hashtable<int,T> where the ints were clearly contiguous in [0,n) and an array would be perfectly good. Now I know: It's not okay for code to have that old person smell. If you can't remember basic coding stuff then you don't have the memory capacity to take advantage of the experience that you have.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

sarehu posted:

I interviewed somebody senior once and, being new, decided to overlook the use of a hashtable<int,T> where the ints were clearly contiguous in [0,n) and an array would be perfectly good. Now I know: It's not okay for code to have that old person smell. If you can't remember basic coding stuff then you don't have the memory capacity to take advantage of the experience that you have.

Yeah this really just added up. Beyond the weirdness around Java's referencing(Strong/Weak/Soft/Phantom), he was also a little bit concerningly vague about IOC strategies - he was able to name 'Dependency Injection' but when pressed for some specifics, couldn't quite define Constructor/Property Injection, Service Location, not even just using a Factory(from a Java dev!)

Along with other random bullet points on his resume, I tried to ask for a bit of a differential opinion with related tech. Why Angular over other things? Why would you use Mongo instead of traditional DBs? When is node appropriate rather than something like Apache? He just kind of...it was quick StackOverflow level quips rather than what I'd have liked/expected, which is at least one or two very serious "here is the razor used to decide when this tech is appropriate to the solution" points.

I guess for a guy who talked up how much he was just fascinated by the tech - how he spent lots of his personal time working with and around it, it just felt very weird to not be able to get into a *technical discussion*.

csammis
Aug 26, 2003

Mental Institution

Cuntpunch posted:

I guess for a guy who talked up how much he was just fascinated by the tech - how he spent lots of his personal time working with and around it, it just felt very weird to not be able to get into a *technical discussion*.

In my experience this scenario isn't that unusual when it comes to interviewing. The "fascinated by tech" story is easy to fabricate when you're trying to show that you're not just another worker drone, you're really interested. Good for you for probing deeper into things and discovering that it was masking a lack of depth.

Mniot
May 22, 2003
Not the one you know

Cuntpunch posted:

I guess for a guy who talked up how much he was just fascinated by the tech - how he spent lots of his personal time working with and around it, it just felt very weird to not be able to get into a *technical discussion*.

I work with a guy who is (honestly) fascinated by tech and enthusiastic about working with it and has been in the business for like 30 years and he's just hopeless. I draw him a diagram: "these 4 services are running on every one of our machines. We have 4 machines and they are configured exactly the same way." He spends the rest of the week SSHing to each machine and being puzzled that they all look the same. Then the next week he asks me where our services run. His supervisor is not concerned.

FamDav
Mar 29, 2008
Why node vs Apache though

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

FamDav posted:

Why node vs Apache though

Because he wanted to talk about his personal projects which largely involved a MEAN stack(everything except Express was listed on his resume as a bulletpoint). Also because it was listed next to the usual HTML5/JavaScript/CSS bulletpoint. So we're specifically talking using it as an HTTP endpoint, at which point why not ask it - especially when he lists a bunch of other Apache projects like Camel and Ant on his tech.

There's no right answer - I'm not a fan of factoid based interviewing, I'd prefer to have a discussion - but I'd expect some sort of answer other than "Well, Node is really fast because of the event, uh, uh, gosh what is it called, I can't think of the name right now"

B-Nasty
May 25, 2005

Cuntpunch posted:

It looked ROUGHLY like:

At least you got something almost resembling a (in)correct answer. I once asked a candidate to write a few basic statistical functions (mean, median) -- and I provided the formula -- with some unit tests. In 45+ minutes, there wasn't a program that would compile or even the basic start of a correct function.

This was a guy who sounded pretty convincing and confident during the high-level-talking stage. Once keys hit keyboard, that confidence just completely evaporated.

MrMoo
Sep 14, 2000

I'm looking at four on-site coding interviews in the coming week all in startups of various descriptions :derp: I've managed to go through three languages in one coderpad screen already because I didn't want to touch a nested array of arrays of arrays in <language-of-choice>. One of them is a second on-site but with different people, only 2 hours :shrug:

spiritual bypass
Feb 19, 2008

Grimey Drawer
Now's the time to get ambitious with the salary requirements!

:homebrew:

MrMoo
Sep 14, 2000

Received a random call at 2pm which was an hour long tech screen before a planned one at 4:30. I do not understand how this code actually appears to produce the correct results, the calculation of maximum cost is weird. I am dangerous with algos.
Java code:
 private static int maximumCost (Vector<Job> jobs) {
     Deque<Job> running = new ArrayDeque<Job> ();
     int max_cost = 0;        
     int time = 0;
     for (int i = 0; i < jobs.size(); i++) {
        time = jobs.get(i).begin;        
        running.push (jobs.get(i));
        max_cost += jobs.get(i).cost;
            
        /* find jobs that have finished */
	    for (Iterator<Job> it = running.iterator(); it.hasNext();) {
			Job job = it.next();
            if (time > job.end) {
                max_cost -= job.cost;
				running.remove (job);
            }
        }   
     }
 
     return max_cost;
 }

baquerd
Jul 2, 2007

by FactsAreUseless

MrMoo posted:

Received a random call at 2pm which was an hour long tech screen before a planned one at 4:30. I do not understand how this code actually appears to produce the correct results, the calculation of maximum cost is weird. I am dangerous with algos.
Java code:
 private static int maximumCost (Vector<Job> jobs) {
     Deque<Job> running = new ArrayDeque<Job> ();
     int max_cost = 0;        
     int time = 0;
     for (int i = 0; i < jobs.size(); i++) {
        time = jobs.get(i).begin;        
        running.push (jobs.get(i));
        max_cost += jobs.get(i).cost;
            
        /* find jobs that have finished */
	    for (Iterator<Job> it = running.iterator(); it.hasNext();) {
			Job job = it.next();
            if (time > job.end) {
                max_cost -= job.cost;
				running.remove (job);
            }
        }   
     }
 
     return max_cost;
 }

You sure that call wasn't at 2AM? I refuse to believe this code actually works.

MrMoo
Sep 14, 2000

Check it out: https://is.gd/OMjCsI

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Is it supposed to return the high-water-mark for total cost of running jobs at any time during the schedule?

Because it doesn't do that. Try with two jobs: the first that starts at 1, ends at 2, and has cost 100; the second that starts at 3 and ends at 4, and has cost 1. The algorithm you posted will return 1.

MrMoo
Sep 14, 2000

ShoulderDaemon posted:

Is it supposed to return the high-water-mark for total cost of running jobs at any time during the schedule?

Yes, I have three very bad options so far and they're not really getting better. The idea with this version is to walk through a (sorted) list of time events and increment the cost as each job starts and decrement as they end.

MrMoo fucked around with this message at 02:39 on Aug 13, 2016

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

MrMoo posted:

Yes, I have three very bad options so far and they're not really getting better. The idea with this version is to walk through a sorted list of time events and increment the cost as each job starts and decrement as they end.

Your "max_cost" variable should actually be called "current_total_cost", if that helps. Once you have that, maximizing should be easy.

MrMoo
Sep 14, 2000

Ok, looks a bit better now. Still seems odd I never have to do much with the begin time but as they only have to overlap for at least one time unit it works.
Java code:
 private static int maximumCost (Vector<Job> jobs) {
     Deque<Job> running = new ArrayDeque<Job> ();
     int cost = 0, max_cost = 0;        
     int time = 0;
     for (int i = 0; i < jobs.size(); i++) {
        time = jobs.get(i).begin;        
        running.push (jobs.get(i));
        cost += jobs.get(i).cost;
            
        /* find jobs that have finished */
        for (Iterator<Job> it = running.iterator(); it.hasNext();) {
            Job job = it.next();
            if (time > job.end) {
                cost -= job.cost;
                running.remove (job);
            }
        }   
        if (cost > max_cost) max_cost = cost;
     }
 
     return max_cost;
 }

baquerd
Jul 2, 2007

by FactsAreUseless

MrMoo posted:

Ok, looks a bit better now. Still seems odd I never have to do much with the begin time but as they only have to overlap for at least one time unit it works.

Java code:
 private static <GOON extends Job> int maximumCost(List<GOON> jobs) {
     Deque<Job> running = new ArrayDeque<>();
     int cost = 0;
     int maxCost = 0;   
     
     for (Job job : jobs) {   
        running.push(job);
        cost += job.cost;
            
        //find jobs that have finished and remove their cost from current count
        for (Job jobToCheck : running) {
            if (job.begin > jobToCheck.end) {
                cost -= jobToCheck.cost;
                running.remove(jobToCheck);
            }
        }
         
        if (cost > maxCost) {
            maxCost = cost;
        }
     }
 
     return maxCost;
 }

MrMoo
Sep 14, 2000

Ooh, yes that brings better clarity, thanks "Linus Torvalds". As a polyglot I start with the lowest common denominator and see a big warning about invalidating the iterator on the collection on the remove(). Per the documentation that should fail with an ArrayList instead of a synchronized Vector because the modification is outside the implicit iterator of the foreach loop.

MrMoo fucked around with this message at 16:51 on Aug 13, 2016

baquerd
Jul 2, 2007

by FactsAreUseless

MrMoo posted:

Ooh, yes that brings better clarity, thanks "Linus Torvalds". As a polyglot I start with the lowest common denominator and see a big warning about invalidating the iterator on the collection on the remove(). Per the documentation that should fail with an ArrayList instead of a synchronized Vector because the modification is outside the implicit iterator of the foreach loop.

Yeah, you should really be just using iterator.remove().

MrMoo
Sep 14, 2000

I guess they liked it as they are lining up another interview :lol: Another company said I "crushed it", giving a JavaScript answer of all things.

Today I had a pretty quick 30 minute interview which was a weird set of fast questions on C++11 including "what is the most misfortunate feature of C++11?" idk :wtf:

I was interviewed on C++11 by a vendor of the company I am actually applying to and which are a Java house and the interviewer in question is a networking engineer :derp:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

MrMoo posted:

I guess they liked it as they are lining up another interview :lol: Another company said I "crushed it", giving a JavaScript answer of all things.

Today I had a pretty quick 30 minute interview which was a weird set of fast questions on C++11 including "what is the most misfortunate feature of C++11?" idk :wtf:

I was interviewed on C++11 by a vendor of the company I am actually applying to and which are a Java house and the interviewer in question is a networking engineer :derp:

Question is so easy if you're familiar with C++11. Just spitballing what you like or don't about it. I should read what's all in 17 now you mention it.

Do you have C++ on your resume?

MrMoo
Sep 14, 2000

Well I don't like the lack of make_unique and that was fixed in C++14, but the implication was on a mistake in the release, I know the bits I like as they make things better.

I think the question was looking for acquire/release semantics around volatile

I use C++14 but I'm no expert on templates, more critically I say I'm not a Java developer either but this is a Java developer role, ha.

MrMoo fucked around with this message at 13:58 on Aug 16, 2016

GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer
I know C++ pretty well, but would struggle with that question, assuming it means "features that are in C++11 and not in prior releases".

Maybe I'd go for:

- The introduction of std::bind, which was almost wholly useless even in C++11 and is entirely useless in C++14;
- Personal taste - I don't like that std::thread begins executing on construction (edit: ah - apparently this might be a necessity on some platforms);
- The standardisation of the clunkier e.g std::enable_if<T>::type rather than C++14's less clunky e.g. std::enable_if_t<T>;
- Making constexpr methods implicitly const (rescinded in C++14).

GeneralZod fucked around with this message at 14:14 on Aug 16, 2016

Hughlander
May 11, 2005

Std::bind owns when used with objective c++

Xarn
Jun 26, 2015

MrMoo posted:

"what is the most misfortunate feature of C++11?" idk :wtf:

Let me tell you about std::memory_order_consume and friends. :v:

It was underspecified, impractical and possibly unimplementable. IIRC it is being fixed in C++17 (or maybe it was already fixed in C++14, I prefer to keep myself to sequentially consistent atomic variables, unless absolutely necessary).


Also, std::bind is actually from TR1, predating C++11 by quite a lot. :science:

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

Oh yay I have a five round interview in Philly on Thursday and another five rounder in Manhattan on Friday, and these are supposed to be small startups. One of the rounds is a debugging session which admittedly sounds pretty cool, another one slightly concerning is called a "behavioral interview".

  • Locked thread