Programming

Congrats!

How about a TR?

1 Like

Yeah congrats. I would love to get an idea of the questions

1 Like

You didn’t even say PC or Mac, but look at preferences → settings → window → restore windows and set to “all”. Pretty hard to diagnose “randomly forgets” though.

Yeah, I’ve tried everything obvious the internet suggested. I posted a very slightly more detailed version a few days ago, although “randomly forgets” is all I really have. I doubt it’s useful info and I’m probably never getting an answer anyway, but I use Windows/WSL.

Opening the folder I was working in always brings them back for me.

I’m still on good 'ol Sublime. It sucks, but it does everything I need, and I know all its quirks.

Could it be the way you’re opening or closing VS code? As long as I quit Sublime all at once with Ctrl-Q, or it crashes, I’m fine. But if I close my current project before quitting, or do some other things that I can’t remember right now, then I’m fucked when it reopens.

Probably, but I have another interview scheduled that could be a contender, so we’ll have to see. They also haven’t provided comp details yet, so…

Interview itself was weird–75% of the interview was behavior/unstructured Q&A. The coding questions were very easy. One was clearly supposed to be “the hard one,” and it was basically find the maxes of given-size sliding windows in an array.

1 Like

Did they want efficiency for that? I could do that in like one line of code but it wouldn’t be very efficient.

It’s very unclear what they wanted. I asked about validating inputs, and was brusquely told that they didn’t care about that. So I started coding something with a heap, got momentarily hung up on the fact that Python’s god-awful heap doesn’t let you delete things from the heap. Before I had a chance to work through that, he said he “might be willing to overlook it” if I could tell him the time complexity of removing an item from the heap. So I told him, while explaining how you would go about doing it with an array-based heap. Then he interrupted to point out that the array was an implementation detail, and what if the heap was, counterfactually, a tree. And then after I answered that, he said he was satisfied and ended the coding section even though we were less than halfway through the allotted time, so we spent the rest of the time chatting.

And then in response to one of my questions he offhandedly mentioned that he did about 20 interviews per person who got hired. He then went back to clarify that he meant 20 onsites, not just screening interviews.

Like I said, it was weird.

Python heap is so bad.

The problem is given a sequence of numbers, return a new sequence with the max of the previous K numbers at each index?

A heap is good, each item will get inserted and deleted at cost log N, so the total is N log N.

What if you only kept the last K elements around though? Then your cost would be N * (something in terms of K), which will be better when N >> K.

So you want a data structure that allows arbitrary delete and cheap max. How about a queue and a binary tree?

When the item ages out of the queue – beyond K from index – remove it from the tree. Insert, delete, and get max all cost log K. So the total cost is N log K.

Does this work? I don’t think you can do better because log K for sorting is cheap.

The way I did it, the heap always had k items, so it should be N log k. I vaguely recall a linear time solution I saw on LC. The basic idea is that if you have two numbers X and Y separated by less than k, nothing in the middle is relevant. So you can use a deque, iterate over the list, and at each step, pop everything in the deque that’s smaller than the current number off, then push the current number on. Then the left side of the deque should be the maximum from the current window, and you pop it off when it leaves the window. Possibly some details off there, but I think that was the general idea.

That’s clear and good, thanks.

I don’t think your heap can always have K items. To do so you have to remove something which is not the max element, which isn’t how heaps work.
Your python heap is exposed as a python list so you can remove, but that cost is linear, so total cost is N * K^2.
What am I missing?

The dequeue is good.

You can transpose the element to be removed with the last element of the list, then delete the last element. Now you have a rogue element in the middle of the list, but you can simply sift it up or down to fix the heap.

Update: I took the job. I’m officially a technology brother now!

Also, wtf is going on with comp? The offer was 50% more than I thought was the max realistic amount I’d be able to get. It’s bonkers.

6 Likes

Congratulations!

You’re still a newb until you’re bitter that your comp is too low.

5 Likes

Market’s wild right now. Congrats btw!

1 Like

I was looking for some examples of clean coding in Python and found results along these lines:

https://towardsdatascience.com/python-clean-code-6-best-practices-to-make-your-python-functions-more-readable-7ea4c6171d60?gi=74ecc0566b9e

Some of the guidelines seemed a little extreme to me and counter to how the APIs of several widely used packages are designed. For example, one article recommends that functions should not have more than 3 arguments, and another recommends that functions shouldn’t have flags (e.g., a parameter that determines whether the output will be in miles or kilometers).

Is this type of stuff considered to be guiding principals that can be outweighed by other concerns in certain cases, or are clean coding practitioners sticklers about this sort of thing?

Generally once the function gets to 2-3 parameters-ish is when I decide to just pass an object that can grow to as many parameters as needed w/o upsetting the method signature. Otherwise you can wind up with annoying method calls like someFunction(“bob”, null, null, 1, null, 47).

But it’s not like this stuff set in concrete or anything. For something like too many method parameters, it’s almost better to just learn on your own why that can get annoying imo.

I’ve never heard the thing about flags. How do they recommend handling the miles/km case - two separate functions? That might be cleaner I guess depending on the context. That or convert the result after getting it from the function.