News for hackers. Stuff that matters.
Re:Ask HN: Joining Big Tech in One’s 40s by decebalus1 on Tuesday January 07, 2020 @03:44PM (#21984598)
You advice is sound but incomplete.

> if you still understand your undergraduate level algorithms course and the corresponding vocabulary, then you know what you need to know

speaking from experience, this would not get you nowhere near the level you have to be for passing the Google interview (or any other FAANG interview for that matter). You need to study long and hard in addition to solving OJ problems and familiarize yourself with different problem patterns. Let me give you and example of what I got at Google: https://leetcode.com/problems/remove-duplicate-letters/ Solving this problem optimally with only what you remember from undergrad algo courses is impossible. You either need to have a knack for these types of challenges or solve enough of them to identify a solution pattern.

Re:Ask HN: Joining Big Tech in One’s 40s by jefftk on Tuesday January 07, 2020 @04:58PM (#21985438)
For what it's worth, I've interviewed 200+ engineers at Google and I think the problem you linked is not a good interview problem. I'm sorry you were asked it!

A good problem gives people with algorithms ability a space to demonstrate that, but it should also give space for demonstrating strengths in design, coding, communication, etc. This one is almost all algorithms, of the "have you seen things like this before" variety, plus a small amount of code.

Re:Ask HN: Joining Big Tech in One’s 40s by seanmcdirmid on Tuesday January 07, 2020 @05:04PM (#21985513)
Does Google interview training emphasize that? Even in companies that claim not to give leetcode questions, they do pop up; everyone isn't really on the same page and there seems to be a lot of luck involved.
Re:Ask HN: Joining Big Tech in One’s 40s by jefftk on Tuesday January 07, 2020 @05:29PM (#21985821)
I went through interview training 5+ years ago, but that was covered then and I believe it's still covered now. Because interviews are mostly conducted by engineers who do it as an occasional thing there are many inexperienced interviewers.

(Speaking only for myself)

Re:Ask HN: Joining Big Tech in One’s 40s by joshuamorton on Tuesday January 07, 2020 @08:03PM (#21987169)
Yes.

The other important bit is that you often don't need to just find the optimal solution to get good ratings. For the question I used to use, I've had perhaps one person get the optimal solution without any hints. None have solved the extensions without hints. I've given more than one Strong Hire rating.

Re:Ask HN: Joining Big Tech in One’s 40s by matt-attack on Tuesday January 07, 2020 @04:23PM (#21985047)
> You must make sure your result is the smallest in lexicographical order among all possible results.

Can someone explain this? I can't even parse that sentence.

Re:Ask HN: Joining Big Tech in One’s 40s by Blakestr on Tuesday January 07, 2020 @04:48PM (#21985306)
Basically alphabetical order, but if you don't say lexicographical, it doesn't sound as smart. (I am assuming it's a more comprehensive term, having to do with other characters, other than simple letters, so that if integers were used, it would appear as 1234, where saying "in alphabetical order"doesn't make sense. But yeah, I did a double take.
Re:Ask HN: Joining Big Tech in One’s 40s by grahamburger on Tuesday January 07, 2020 @11:42PM (#21988419)
If you remove the duplicates from the string:

CACB

You can get either CAB or ACB. If you were to order all of the possible results of removing duplicates (in this case only two, but obviously many more for more complex strings) and order them alphabetically, then take the lowest one, that would be the right answer.

Re:Ask HN: Joining Big Tech in One’s 40s by kayoone on Tuesday January 07, 2020 @04:45PM (#21985264)
in other words, the shortest string in alphabetical order
Re:Ask HN: Joining Big Tech in One’s 40s by shric on Tuesday January 07, 2020 @04:56PM (#21985406)
Smallest as in order not length.

In the second example with input cbacdcbc a possible solution would be cbad but acdb is "smaller" (ordered before).

Re:Ask HN: Joining Big Tech in One’s 40s by logfromblammo on Tuesday January 07, 2020 @06:39PM (#21986515)
It seems odd to want to preserve the ordering among the surviving letters while still involving alphabetical order somehow. Those motives are usually mutually exclusive in the real world.

As an engineer, before starting to code, I'd first ask if the customer would prefer "abcd" or "cbad" for the second example, as either would be far cheaper in terms of development and maintenance costs to do. It's somewhat common to discover that they're just taking the "acdb" you're giving them because that's exactly what they asked for, and then they're alphabetizing it to "abcd" afterward on their end, anyway. But sometimes, there is a legit reason for the weirdness, and the customer is willing to pay for the extra effort.

Whenever someone seems intent on aiming at foot and pulling trigger, always ask "Are you sure?" and "Why do you want that?" at least once before helping them do what they want.

The "read hypothetical; code answer" type of test doesn't quite capture that like the interactive interview discussion does.

Re:Ask HN: Joining Big Tech in One’s 40s by hiram112 on Tuesday January 07, 2020 @11:08PM (#21988216)
As I'm in a similar boat to the OP, this is exactly why I'm hesitant to even interview with any of these companies, even as a test to see where I stand, simply because I fear I'd be blacklisted on some list these companies might share, should I bomb one without a lot of time spent reviewing.

I sometimes follow a Reddit sub geared for mostly recent CS grads. Every week or two will be a post from someone who got a FAANG job, detailing what he did in order to pass the interview. And some of these are pretty absurd - graduating last semester and since then spending 6 months going through leetcode 6 hours a day, studying algorithms, paying for interview training classes, etc.

And as an older guy who has a decent CS degree but hasn't needed to use 90% of anything related to algorithms in 15 years, I'd have to study a lot, and along with the numerous days of vacation time used for these interviews in California, it doesn't seem worth the effort.

Re:Ask HN: Joining Big Tech in One’s 40s by hiyer on Friday January 10, 2020 @03:23AM (#22009357)
> I fear I'd be blacklisted on some list these companies might share, should I bomb one without a lot of time spent reviewing.

AFAIK they only blacklist you for 6 months and then you can try again. Even that may be relaxed if you're trying for a different department or, especially, geographical location.

> numerous days of vacation time used for these interviews in California, it doesn't seem worth the effort.

In India at least, the big companies handle this better than smaller ones - they have one or two telephonic interviews to begin with and then finish off all the face-to-face interviews in a single day.

Re:Ask HN: Joining Big Tech in One’s 40s by grahamburger on Tuesday January 07, 2020 @11:38PM (#21988404)
Well this was a fun distraction! Took my no-CS-degree self a few tries to get it, but I got it[1]. I doubt I could have done it very well in an interview setting, though. A bit trickier than it looks at first for sure. Good practice because I have a coding interview tomorrow.[2]

12ms w/ 2.1MB memory usage - apparently 25 percentile for speed and lower memory usage than 100% of submissions in ~50 lines of Go.

[1] https://leetcode.com/submissions/detail/292246392/ (Not sure if you can deep link in to leetcode like this?)

[2] I am looking for a job! Hit me up! https://news.ycombinator.com/item?id=21937576

Re:Ask HN: Joining Big Tech in One’s 40s by Kaius on Thursday January 09, 2020 @08:58AM (#22001181)
> [1] https://leetcode.com/submissions/detail/292246392/ (Not sure if you can deep link in to leetcode like this?)

It seems you cannot, 404 error.

Re:Ask HN: Joining Big Tech in One’s 40s by MaximumYComb on Tuesday January 07, 2020 @06:27PM (#21986419)
I've just finished the 2nd year of my CS degree. In about 3 minutes I came up with:

1) create an empty string, call it "S2" 2) loop over each char in original string 3) if the char isn't in S2, add it to the end of S2. If the char is already present in S2 then lexicographically compare the prior S2 verse S2 with this char shifted to the end. Keep the lower ordered one.

This took about 3-4 minutes of thinking and is O(n). It might not be optimal, it might not even be a correct solution as I've spent only a few minutes on it. However, I feel it's close and it wouldn't take much to flesh out.

EDIT: This solution is incorrect.

Re:Ask HN: Joining Big Tech in One’s 40s by thaumasiotes on Tuesday January 07, 2020 @07:09PM (#21986744)
Here's what I came up with after experimenting with handling the leetcode example ("given cbacdcbc, produce acdb") manually:

Build a suffix tree ( https://en.wikipedia.org/wiki/Suffix_tree ) of the input with two modifications:

1. When adding a letter to the suffix tree, skip any paths that already contain that letter. (Thus, each path will contain a given letter no more than once.)

2. Include accounting information in each node specifying the length of the longest suffix including that node.

From wikipedia, construction of an ordinary suffix tree takes time and space linear in the length of the input string. At this level of analysis, I'm just hoping that modification #2 doesn't affect that. #1 certainly won't, in that it involves spending less time and less space than otherwise (by bailing out early under some circumstances).

Once the tree is constructed, just walk it, selecting at every point the child that is lexicographically earliest among all children with the maximum suffix length.

Observation: constructing this tree by hand really feels exponential; I suspect that the linear time and space requirements lean on an assumption that the size of the alphabet is finite.

Observation #2: Based on the comment timestamps, this took about 40 minutes of thinking. I think it's a good solution, but it probably wouldn't look great in an interview. (Also, handwaving "construct a suffix tree" is fast, but actually producing the code to do it takes extra time.) :/

Observation #3: assuming your solution is correct, it is essentially a reduction by dynamic programming of this one, only doing the calculations that are necessary to produce the lexicographically earliest string where I produce them all.

Re:Ask HN: Joining Big Tech in One’s 40s by thaumasiotes on Wednesday January 08, 2020 @08:28AM (#21991197)
After playing with suffix trees a little more, I need to make a correction:

This problem asks for subsequences rather than substrings. As a result, when adding a node to the "suffix tree", it will need to be added as the child of more nodes than it would if we were building an actual suffix tree.

This seems like the type of change that might make construction of the tree harder than O(n). In particular, it will violate the constraint that a suffix tree for a string of length n has only n leaves.

Re:Ask HN: Joining Big Tech in One’s 40s by mmierz on Tuesday January 07, 2020 @07:17PM (#21986803)
That solution as written is O(n^3)

This is not an easy problem.

Re:Ask HN: Joining Big Tech in One’s 40s by MaximumYComb on Tuesday January 07, 2020 @07:51PM (#21987078)
You only check each character in the string once. A hashmap can check if the char is used already.

For each char in the original string there is: * 1 check in hashmap (let's assume it was found). This is O(1) * build a new string where we remove that char from the string we are building (string2) and add it to the end. This step may look O(n) initially since we need to find that char in string2 but string2 is capped at 26 characters so it's O(1) * One comparison between the string we are building and the altered version.

How does that make it O(n^3)? I can't see which step inside the initial loop is O(n) or greater.

EDIT: The solution is actually incorrect so this is now semantics.

Re:Ask HN: Joining Big Tech in One’s 40s by thaumasiotes on Tuesday January 07, 2020 @10:38PM (#21988034)
> EDIT: The solution is actually incorrect so this is now semantics.

Interesting use of "semantics".

The question of "how fast does this algorithm run?" is totally independent from the question of "what does this algorithm do?"; the second one is semantic but you're discussing the first here.

Re:Ask HN: Joining Big Tech in One’s 40s by MaximumYComb on Wednesday January 08, 2020 @09:59PM (#21998153)
The algorithm I described was O(n), you said it was O(3). I'm assuming this happened because my algorithm was actually an incorrect solution but you subconsciously added in steps to make it a correct algorithm which changed its complexity. Hence it's semantics because we seem to be discussing two different algorithms.
Re:Ask HN: Joining Big Tech in One’s 40s by thaumasiotes on Tuesday January 07, 2020 @10:14PM (#21987933)
Can I ask about the suffix tree solution? A one-hour problem is still pretty easy in the grand scheme of things.
Re:Ask HN: Joining Big Tech in One’s 40s by 171243 on Tuesday January 07, 2020 @07:15PM (#21986786)
input: "bcabc"

  1. "b"
  2. "bc"
  3. "bca"
  4. "bca"
  5. "bca"
What am I missing?
Re:Ask HN: Joining Big Tech in One’s 40s by kangnkodos on Wednesday January 08, 2020 @12:47PM (#21993824)
Take all the possible answers with duplicates removed, and return the first one in alphabetical order.

input: "bcabc"

output: "abc"

Re:Ask HN: Joining Big Tech in One’s 40s by MaximumYComb on Tuesday January 07, 2020 @07:54PM (#21987107)
Nothing. I hadn't fleshed out my idea yet and that's the error I thought could exist. My solution is wrong.
Re:Ask HN: Joining Big Tech in One’s 40s by pizza_dave on Wednesday January 08, 2020 @02:56PM (#21995102)
that is a single line of code in javascript, assuming you just want the value in #5 const foo = [...new Set('bcabc'.split(''))].join('')
Re:Ask HN: Joining Big Tech in One’s 40s by sfgweilr4f on Tuesday January 07, 2020 @10:57PM (#21988150)
I think I'd rather solve real problems than some basic algo I'd never bother to write myself. If Google just wants basic algos and will likely filter me out during interview because of that, I'd sooner not bother. This is probably why big companies complain of talent shortages. Also why they forget real people and start going on very strange tangents. Stupid filters. Good.

I'll stick with creating actual solutions for real people with real problems. So much easier. shrug

Re:Ask HN: Joining Big Tech in One’s 40s by krn on Tuesday January 07, 2020 @05:16PM (#21985675)
> Let me give you and example of what I got at Google: [...] Solving this problem optimally with only what you remember from undergrad algo courses is impossible. You either need to have a knack for these types of challenges or solve enough of them to identify a solution pattern.

I have never tried to solve such problems before, but wouldn't it be enough to convert the string into a set of chars, then into an array of chars, sort it, and return it as a string?

Re:Ask HN: Joining Big Tech in One’s 40s by decebalus1 on Tuesday January 07, 2020 @05:21PM (#21985730)
> wouldn't it be enough to convert the string into a set of chars, then into an array of chars, sort it, and return as a string?

No. Please re-read the problem statement. It's way more complicated than that. If you figure out how to do it, try to figure out how to do it in O(N).

Re:Ask HN: Joining Big Tech in One’s 40s by mason55 on Tuesday January 07, 2020 @06:12PM (#21986283)
The proposed solution isn’t optimal but it works. Not sure what you think is wrong with it?

An optimal solution would be something like

- create an array of 26 or 52 bytes depending on whether this is case sensitive

- iterate over the string and set the byte corresponding to each letter’s position in the alphabet to 1

- iterate over the byte array and for each 1 you encounter print out the corresponding letter

Re:Ask HN: Joining Big Tech in One’s 40s by mmierz on Tuesday January 07, 2020 @07:24PM (#21986868)
>The proposed solution isn’t optimal but it works. Not sure what you think is wrong with it?

Consider the input “ba”

This solution will return “ab”, which is not a strong that can be generated by deleting characters from the input.

Re:Ask HN: Joining Big Tech in One’s 40s by jfk13 on Tuesday January 07, 2020 @06:30PM (#21986444)
Won't that give you the letters in alphabetical order, which may not be correct? See example 2 on the problem page.
Re:Ask HN: Joining Big Tech in One’s 40s by krn on Tuesday January 07, 2020 @07:23PM (#21986862)
> Won't that give you the letters in alphabetical order, which may not be correct?

But that's what "lexicographical" means?

> In mathematics, the lexicographical order is a generalization of the way words are alphabetically ordered based on the alphabetical order of their component letters.

> This generalization consists primarily in defining a total order on the sequences (often called strings in computer science) of elements of a finite totally ordered set, often called an alphabet.

https://en.wikipedia.org/wiki/Lexicographical_order

Re:Ask HN: Joining Big Tech in One’s 40s by Twisol on Tuesday January 07, 2020 @10:46PM (#21988085)
I think the problem statement wants the lexicographically least string of those obtainable by deleting characters.