Sie sind auf Seite 1von 17

MY SUBREDDITS

FRONT - ALL - RANDOM | ASKREDDIT - FUNNY - TODAYILEARNED - PICS - GAMING - VIDEOS - NEWS - WORLDNEWS
MORE -

CSCAREERQUESTIONS

comments

This is an archived post. You won't be able to


vote or comment.

Here's a pretty big list of


405 programming interview questions I
compiled while studying for big 4
interviews. I think you guys will find
it useful! (self.cscareerquestions)

Want to join? Log in or sign up in seconds. | English

search

Submit Query

this post was submitted on 13 Mar 2014

405 points (99% upvoted)


shortlink:

https://redd.it/20ahfq

username

password

remember me

reset password

login

submitted 2 years ago * by dandr01d

General

Find the most frequent integer in


an array

Find pairs in an integer array


whose sum is equal to 10 (bonus:
do it in linear time)
Given 2 integer arrays, determine
of the 2nd array is a rotated
version of the 1st array. Ex.
Original Array A={1,2,3,5,6,7,8}
Rotated Array B={5,6,7,8,1,2,3}
Write fibbonaci iteratively and
recursively (bonus: use dynamic
programming)

Find the only element in an array


that only occurs once.
Find the common elements of 2
int arrays
Implement binary search of a
sorted array of integers
Implement binary search in a
rotated array (ex.
{5,6,7,8,1,2,3})

Use dynamic programming to find


the first X prime numbers
Write a function that prints out
the binary form of an int

discuss this ad on reddit

Ask a new question

cscareerquestions
subscribe

67,480 readers

131 users here now

WELCOME one and all, to /r/cscareerquestions!


Here we discuss careers in Computer Science,
Computer Engineering, Software Engineering,
and related fields. Please keep the conversation
professional, adhere to the reddiquette, and
remember to READ OUR RULES.

Want to ask a question?


First: Read the rules

Second: Check the FAQ

Third: Search for prior posts on the


subject
Fourth: Post post post

User Flair??

Noticed some cool user flair around? Take a


look through this thread to see what it's all
about.
tl;dr - darker colors == more posting
experience here.

Implement parseInt

Implement squareroot function

Implement an exponent function


(bonus: now try in log(n) time)

Write a multiply function that multiples


2 integers without using *
HARD: Given a function rand5() that
returns a random int between 0 and 5,
implement rand7()
HARD: Given a 2D array of 1s and 0s,
count the number of "islands of 1s"
(e.g. groups of connecting 1s)

Strings

Find the first non-repeated character in


a String
Reverse a String iteratively and
recursively

Determine if 2 Strings are anagrams


Check if String is a palindrome

Check if a String is composed of all


unique characters
Determine if a String is an int or a
double

HARD: Find the shortest palindrome in


a String

HARD: Print all permutations of a String

HARD: Given a single-line text String


and a maximum width value, write the
function 'String justify(String text, int
maxWidth)' that formats the input text
using full-justification, i.e., extra spaces
on each line are equally distributed
between the words; the first word on
each line is flushed left and the last
word on each line is flushed right

Trees

Implement a BST with insert and delete


functions
Print a tree using BFS and DFS

Daily Threads

In addition to a chat thread that's newly


spawned every day, we have a daily rotation for
threads for certain topics. Please don't start
new threads about these topics without getting
mod permission first, lest we be forced
to...intervene.
Sunday: Big 4

Monday: Interviews
Tuesday: Resumes
Wednesday: Big 4

Thursday: Interviews

Friday: Special Rant Thread


Saturday: Resumes

Related Subs

CS Interview Questions
Learn Programming

General Programming Discussion


Coding

CS Theory

CS Education

IT Career Questions
Telecommuting

General Job Discussion


Digital Nomads

Contribute to the FAQ!

We could always do with more help and


wisdom, friend! The better the FAQ, the harder
we can come down on lazy posters with loweffort OPs, which means a higher quality
subreddit experience for you.

Don't see your link?


created by [deleted]

a community for 5 years

Write a function that determines if a


tree is a BST
Find the smallest element in a BST

Find the 2nd largest number in a BST

Given a binary tree which is a sum tree


(child nodes add to parent), write an
algorithm to determine whether the
tree is a valid sum tree
Find the distance between 2 nodes in a
BST and a normal binary tree

Print the coordinates of every node in a


binary tree, where root is 0,0
Print a tree by levels

Given a binary tree which is a sum tree,


write an algorithm to determine
whether the tree is a valid sum tree
Given a tree, verify that it contains a
subtree.

HARD: Find the max distance between


2 nodes in a BST.
HARD: Construct a BST given the preorder and in-order traversal Strings

Stacks, Queues, and Heaps

Implement a stack with push and pop


functions
Implement a queue with queue and
dequeue functions

Find the minimum element in a stack in


O(1) time
Write a function that sorts a stack
(bonus: sort the stack in place without
extra memory)
Implement a binary min heap. Turn it
into a binary max heap
HARD: Implement a queue using 2
stacks

Linked Lists

Implement a linked list (with insert and


delete functions)
Find the Nth element in a linked list

discuss this ad on reddit


MODERATORS

message the moderators

CriticDanger Software Engineer


yellowjacketcoder
fecak Recruiter
Himekat DevOps Engineer
cscareerflairbot Robot
czth Engineering Manager
LLJKCicero Android Developer
AutoModerator Robot

about moderation team

<

>

discussions in /r/cscareerquestions

7 points 11 comments

I've become the "interview guy" - good for


career?

Remove the Nth element of a linked list


Check if a linked list has cycles

Given a circular linked list, find the node at the beginning of the loop. Example:
A-->B-->C --> D-->E -->C, C is the node that begins the loop
Check whether a link list is a palindrome

Reverse a linked list iteratively and recursively

Sorting

Implement bubble sort

Implement selection sort


Implement insertion sort
Implement merge sort
Implement quick sort
71 comments share

all 71 comments
sorted by: best

[] True_Scorpio23 30 points 2 years ago

currently taking Data Structures in Java and Intro to Computer Architecture &
Assembly Language and more than half of these have been required to do my lab
assignments. Thanks for this, I feel more competent and assured for upcoming
internship interviews.
permalink embed

[] Boumbles 92 points 2 years ago

just wait until you haven't touched or done anything similar in a few years and
show up to an interview thinking you know all this stuff and then you choke, curl
up into a ball and just cry until they get security to carry you out to the curb...
permalink embed parent

[+] [deleted] 2 years ago* (5 children)


[] psychicsword Software Engineer

7 points 2 years ago

This is 100% true. I interviewed with Google about a month ago after not doing
any of this kind of stuff for 2 years. I even studied for 3 days straight and I
choked big time. It was a phone interview so security didn't drag me away but I
was fully prepared for the very polite we don't want you at all phone call I got a
few days later.
permalink embed parent

[] rampant_juju 2 points 2 years ago

How exactly does a phone interview work? Wouldn't it be too easy to cheat?
permalink embed parent

[] psychicsword Software Engineer

3 points 2 years ago

Pretty much they asked me to answer a few questions and then write some
code in a google doc. Sure it would be easy to cheat but it is also probably
easy to hear when they are going it. Someone saying "Uhh...." with
ClickClickClick going in the background probably gives it away. You only
have 1 hour to do the interview and ask questions at the end so it ends up
being about 30 minutes to code up the answer for them. Unless you know
your shit to begin with you cant learn an entire topic and answer
performance based followup questions during that time.
permalink embed parent

[] rampant_juju 1 point 2 years ago

No but it would be rather easy to just make a big list of notes or


refer a textbook, wouldn't it?
permalink embed parent

[] psychicsword Software Engineer

4 points 2 years ago

You probably could get away with a single page cheatsheet but
beyond that you probably will be spending more time looking
things up and that will count against you. The questions are also
very academic in nature but still application oriented so you need
to know when, where, and how to use all the different data
structures and quickly adapt them to your needs in the question.
They will then ask you about performance and a bunch of other
things(at least in my interviews) so in order to have a complete
cheat sheet you need to have or remember everything you
probably learned in your first 2 years of CS classes feeding on
your last 2 years of classes. The recruiter I talked to said people
at Google said that the phone interview and the process in
general was harder than the hardest test they had in school but
very similar to a final exam for one of their classes.
After all that the phone interview only gets you a plane ticket to
interview in person where you definitely cant have a cheat sheet
and completely falling apart probably will stick with you longer
because you interview with multiple people. In the end studying
and memorizing all the building blocks is probably the best
approach.
permalink embed parent

[] rampant_juju 1 point 2 years ago

Thank you for the response :)


permalink embed parent

[] Boumbles 2 points 2 years ago

that's ok just reapply next year :)


permalink embed parent

[] psychicsword Software Engineer

3 points 2 years ago

Yea I'm not really concerned in anyway. I have a job I enjoy and gives me
great bonuses and pay raises. I didn't even apply, they found me on
linkedin and asked if I wanted to interview with them. So it didn't really
change anything for me except that I now know that I really need to study
again to keep those skills alive.
permalink embed parent

[] anonmarmot 5 points 2 years ago

I've done that more or less, it was not fun.


permalink embed parent

[] True_Scorpio23 1 point 2 years ago

Haha your post made me laugh not because I don't believe but because I know
its true. Just last semester I was mastering Calc3 and this semester Im taking
mechanical physics and could not remember what a conservative vector field
was precisely. What I have heard though is that companies just what to make
sure you have a strong concept of the different data structures and their
algorithms. Which "I THINK" I can regain once I review my notes. Like I did
with Calc3 material. I take very good lecture notes and study guides based on
lecture and other sources which I save from the very first class I took in college
and as a STEM major it has saved my behind countless of times.
permalink embed parent

[] Zeleres 5 points 2 years ago

It's one thing to know them from doing them in school, it's an ENTIRELY
DIFFERENT thing to be able to whip them up from memory in an interview
(typically in front of several smarter-than-you developers who get hard just
thinking about interrogating people).
permalink embed parent

[] True_Scorpio23 3 points 2 years ago

Most people have said that during interviews you aren't actually coding but
rather writing code on whiteboard where they'll see what your logic and
problem solving skills are like. One of the most common issues I see and have
seen with people since I started a career in STEM is that people think they can
just start coding and eventually arrive at the solution. I always write
pseduocode on paper and really think how certain methods need to interact
with others and just think in general before I even begin to type the skeleton to
my code. Same in math and physics or chemistry, students just start plugging
equations solving for variable and generally don't think what the problem is
asking for to begin with. I have had my share of insulting interviews so I do
know what you're saying but those have been the exception rather than the
rule.
permalink embed parent

[+] [deleted] 2 years ago (4 children)

[] Grammar_misake 7 points 2 years ago

Just a quick question. In these types of interviews how detailed are you supposed to be
on the whiteboard? Say your interviewing for a Java position, do you need to have all the
syntax correct or is it more of a psuedocode type deal to show you have the general idea
of how it works? I rely so heavily on Eclipse and instantly Googling things for reference I
don't think I have much syntax memorized...which is bad I know.
permalink embed

[] robertwilliams Software Engineer

12 points 2 years ago

I do whiteboard interviews to evaluate two things. One, can the candidate figure
out a general approach to solving a problem. Two, do they know language
fundamentals. Can they code their way out of a wet paper bag, so to speak.
I don't think I have much syntax memorized

As an interviewer, I would expect you to know proper syntax for common things in
whatever language you work in (presumably Java), as well as very common API
(substring, working with collections, etc). If you can't write a for loop, then that
would be problematic. Don't know the try-with-resources syntax? That's OK. If you
don't know that substring exists, problem. If you use "put" instead of "add" (or vice
versa) for a collection - not a big deal, that's what IDEs are for. And even if you
mess up on something basic, if you still did fine on the rest of it, I'll overlook that.
permalink embed parent

[] Zeleres 6 points 2 years ago

As an interviewer, I am very sympathetic to the fact you're under stress in the


interview. That said, I'd love for you to just knock it out of the park on your
own - but there's nothing wrong with asking me for help. Quite frankly, I'm
hoping you ask me for help so I can see how you work together with me (do
you dominate the conversation, are you open to new ideas, etc.?)
permalink embed parent

[] nemec 4 points 2 years ago

And don't worry about import/using statements either.


permalink embed parent

[] robertmeta 4 points 2 years ago

If you find a place that is worried about syntax on that whiteboard, be happy you
don't work there. They are hiring the most useless type of human beings.
I have interviewed probably 1000+ people over the past decade and hired about
150, and "whiteboard performance" has no correlation with ANYTHING except -you know -- your ability to whiteboard solutions, which is semi-useless.

The IT industry is starting to pull its collective head out of its ass when it comes to
interviewing. I am a bit sad about that, I have been able to hire absolutely brilliant
people passed over by other shops due to their incredible poor interview systems.
Lots of interview setups exist to make the interviewer feel smart and superior, not
hire the best developer.
permalink embed parent

[] gabriot 2 points 2 years ago

It will help to know the syntax by heart because it shows how familiar you are with
the language, however most interviewers are less interested in the language you
are using and more interested in that you can understand how to implement
concepts to solve issues.
permalink embed parent

[] fahimulhaq 6 points 2 years ago

Take a look at Coderust (www.coderust.com) as well if you are planning to interview in


big tech companies.
permalink embed

[] nanermaner 5 points 2 years ago

Thanks!

permalink embed

[] Paiev 5 points 2 years ago

Find the minimum element in a stack in O(1) time

This is obviously impossible. Maybe there's some constraint you're missing...?

Write a function that sorts a stack (bonus: sort the stack in place without extra
memory)

I'm pretty sure sorting a stack in place is impossible (using only stack operations). For
one thing, accessing the bottom element requires O(n) additional memory, since you
need to store the other elements somewhere.
permalink embed

[] teambritta Software Engineer

2 points 2 years ago

I've seen these questions before.

1) Maintain a stack separate to the original that's always the same height, pushing
the minimum possible element when pushing to the original stack. Pop whenever
the original pops. Peek to see the minimum in O(1) time. Memory use is O(n),
however.
Example:

Original stack = { 1, 2, -1, 5 } Min stack = { 1, 1, -1, -1 }

2) Not 100% sure, but the approach here is to realise 'extra' memory doesn't
preclude an extra variable or two. Simply maintain another stack to push your
data, and perform a stack-based bubble sort, a la Towers of Hanoi.

That is, you don't maintain more that one set of the data, simply divide it amongst
the extra stacks.
permalink embed parent

[] Paiev 2 points 2 years ago

1) Okay, I see what you're saying. You're solving a different problem from "Find
the minimum element in a stack in O(1) time" though. You're augmenting the
stack to create a new data structure which supports finding the minimum in
constant time. Maybe this is what the question is intending. As formed, though,

the question asks "given a stack, find its minimum element in constant time"
which is clearly impossible.

2) You're assuming that when you pop an element from the first stack, the
memory usage decreases. This is not guaranteed (e.g. in an implementation via
an array).
permalink embed parent

[] teambritta Software Engineer

3 points 2 years ago

These are all details the prospective candidate has to ask for/negotiate from
the interviewer. It's not a pop quiz. The whole point is you have to refine
your specification and not repeat some answer you memorised. I'm 99%
sure these two questions are paraphrased from Cracking the Coding
Interview, possibly skipping the nuance of my assumption in both questions.
permalink embed parent

[] potateN- 1 point 2 years ago

Damn you! You scooped me! ;)


permalink embed parent

[] potateN- 1 point 2 years ago

Find the minimum element in a stack in O(1) time This is obviously impossible.
Maybe there's some constraint you're missing...?

Hmm... how about using two stacks? One is just the regular stack. Whenever you
push something to the regular stack, check if it is less than or equal to the top of
the other stack, if so push it there too. When popping from the regular stack, check
if the top of the other stack is the same, if so pop that too. This is 2n space worst
case and the minimum element of the original stack is the top of the other stack.
Write a function that sorts a stack (bonus: sort the stack in place without extra
memory) I'm pretty sure sorting a stack in place is impossible (using only stack
operations). For one thing, accessing the bottom element requires O(n)
additional memory, since you need to store the other elements somewhere.

If the stack is implemented in an array, then popping is just a matter of decreasing


a counter, so you are not really using n additional space to get to the bottom. In
this manner you can simply pop all elements, keep track of the maximum, swap it
with the last element, then push all but the last element. Now do it again, except
the last index is now one less than before. In place sorting (probably even stable if
2.
you are careful) in n
permalink embed parent

[] wagedomain Senior Consultant

7 points 2 years ago

It amazes me how useless most "academic" questions like this are. Especially for front
end development, as almost nothing in this list is used. Let me see how many times
I've used any of these things since I started in the field in 2007...
Well I had to know some of these for other interviews, but other than that, I don't
think I've ever used this stuff in the "real world".

These questions show a very old-school approach to interviewing as well. Some of the
questions I agree with asking, like the fibonacci sequence iteratively and recursively because it shows they understand recursion. I don't see much advantage to many of the
questions, though.
Questions I ask for front end development are things like

What is the CSS Box Model?


In Javascript, what's the difference between == and ===?
In Javascript, how do you fetch an element by it's id? (NOTE: I ask this to see if
people even know that jQuery != Javascript... because lots of people think jQuery is
necessary)
What's your favorite way to make an ajax call (almost all people say jQuery)?
What's a promise? OR say I want to <do something> after two Ajax calls have both
completed, but not before. How can you do this?

The funny thing is, we get a lot of midlevel or senior devs who say they're full stack who
get 0 of these correct. These are people who write Javascript like C#/Java and assume
it's 100% the same. Or because it works, they understand it.
I've also had to fix many, many bugs in JS written by non-front end devs caused by
things like a fundamental misunderstanding of null and undefined types in JS (they're
totally the same, right??).

And funnily enough when I interviewed for a Senior Web Dev (Front End) job I received
zero actual front end questions. All they were interested in was knowing could I write a
LINQ query in C#, did I know hash tables, what's a delegate function in C#, etc.

I've also found no value in straight up programming in interviews. I prefer conversational


approaches. I ask people about projects they've worked on and then get them to deep
dive into something. I get a much better understanding of how the candidate sees
technology and how they think. It also lets me hear their communication skills, and their
enthusiasm.
permalink embed

[+] [deleted] 2 years ago (1 child)

[] khnd 5 points 2 years ago

thanks yo

permalink embed
[] dan1son Lead Software Engineer

6 points 2 years ago

I'm hoping these are only used to decide whether the person actually paid attention
during their computer science classes. These questions should only apply to the very
entry level of positions.

I don't even ask senior developers interviewing to write code. I assume they can do
that... I want to know how they think, how they're able to break up problems, whether
they know WHEN to use these concepts, whether they actually understand the libraries
they claim to know, etc.. Should they be able to accomplish these things listed above?
Sure, I'd expect them to handle most of these problems without much fuss... but do I

care if they can? Does it gain anything by wasting time asking them to reverse a string
by hand? No.
permalink embed

[] ashultz Principal Engineer

1 point 2 years ago

I've interviewed more than a few "senior developers" who could not code in an
interview. The more senior you are the less you may be coding day to day but
when you are coding it is much more likely to be tricky and under time pressure.
Or you will be reviewing someone else's code. So yes, I very much do care if they
can accomplish these things because they may have to do these and much more in
less than ideal circumstances. Whiteboarding is cake compared to fixing a bug
which is currently costing your site thousands of dollars an hour.
permalink embed parent

[] dan1son Lead Software Engineer

7 points 2 years ago

There are better ways to know if someone can code than by asking them to
rewrite functions that have been done for decades. Maybe I used the words
"write code" incorrectly. I do expect them to be able to write out and talk
through how they'd implement things in code (even at a high outline level), but
definitely not simple algorithms from CS101. I need to see database use and
design, design patterns, how they respond to missing information from the
problem description, how they walk through breaking things up into smaller
problems, walking through some code that has known issues to find problems,
etc. I'd rather spend the 30 minutes figuring those things out than whether
they can code out a sorting algorithm from memory.

I just think these simple questions don't show much of any ability to do any
sort of job beyond "implement this function that takes x, and y, and outputs z."
That's not the type of developer people need. Companies need to start
interviewing for skills, not for questions you can find a list of on reddit. If you
can directly study for my interview... I did it wrong.
permalink embed parent

[] teambritta Software Engineer

2 points 2 years ago

In all fairness, these aren't the only questions asked. In my experience


interviewing with companies, both big and small, these CS questions are a
big part, but so are design questions.
I was asked to design a Twitter-based service for Palantir and in a similar
vein, web crawling scale questions for Google. Amazon asked for a class
design for a simple game and added requirements as I progressed to test
my solutions extensibility.
permalink embed parent

[] ashultz Principal Engineer

1 point 2 years ago

And yet, all of those skills are founded on writing functions that take x & y
and output z. A lot of people can write out and talk through... or around...
things they can't actually implement.

A bunch of those specific questions are dumb, like the sorting ones because
the first thing you should know about sorting is that it is trickier than you
think, use the already debugged library functions. And I never want to ask a
common coding question that has a canned answer everyone (should) know.
But I do ask questions at a similar level of complexity.

I agree these are the first level questions, not the end. I want a candidate
senior developer who just smashes my question so I can go on to a design
question that has a lot of boxes and arrows and discussion about what pieces
run on what server and where the messaging goes. But I can't only ask that
since many come through who can't code.
permalink embed parent

[] Quinnjaminn Software Engineer

1 point 2 years ago

While stuff like sorting is basic, and most use cases should just be
delegated to some library sort() function, understanding sorting
algorithms and the tradeoffs can be important, especially in any bit of
code that might be performance critical. Quicksort is your go to sort, but
it's not always the best. Extremely large data sets will probably need an
external merge sort (with potentially some heap sorting on the first
run). Heapsort is O(nlogn) with O(1) extra space, which might be
relevant in low memory scenarios (e.g., embedded). If I ask you what
you'd do in a scenario where you need to sort many nearly-sorted data
sets, and you're more concerned with throughput than tail latency, you
better not say std::sort() or quicksort.
Of course, the relevance of those questions depend on the role you're
applying for.
permalink embed parent

[] ashultz Principal Engineer

2 points 2 years ago

Asking people to write sorts on the board is terrible though because


the concepts are quite interesting but the details are quite fiddly and
thus poor for a whiteboard and because many people will have had
to do the same exercise in class and might have redone it as
interview prep. They're not thinking about how to solve a problem,
they're just trying to spit out quicksort onto the board. Terrible
whiteboard problem.
permalink embed parent

[] iBlaze4sc 10 points 2 years ago

Honestly, I hate questions like these. Having worked in the field for about 2 years
now...you never use any of this crap sans maybe some binary arithmetic . And if you
need to, you google it.
I also do low lvl programming...if that counts for anything
permalink embed

[] teambritta Software Engineer

8 points 2 years ago*

I am two years out of school and been in industry since. I couldn't do them off the
top of my head, but I could certainly give a reasonable solution to most in a 45
minute interview.
No one expects you to recite the perfect answer, you're judged on your approach
to the problem. Instead of judging based on knowledge of frameworks and other
things easily googled, these sorts of questions attempt to level the playing field.
Edit: Typo

permalink embed parent


[] ponchedeburro Consultant Developer

6 points 2 years ago

But demonstrating that you are able to think isn't useless.


permalink embed parent

[] songhyeondeok 2 points 2 years ago

Do you really end up finding these useful? I usually just wing it and it seems fine. Does
preparing actually make a difference
permalink embed

[] Quinnjaminn Software Engineer

27 points 2 years ago*

Keep in mind, there's a world of difference between winging it and barely finishing
in 45 minutes, and being familiar with the topic and easily getting the ideal solution
done in 10 minutes. It's not a binary pass/fail test -- you're trying to leave the best
possible impression on the interviewer.
For instance, in that big thread where a Google employee described his interview
process, he gave a few sample problems. Take the problem of removing duplicate
strings from a data set much larger than memory. If you haven't studied or worked
with external algorithms at all in prep, then that might be a hard problem that
takes you most of the 45 minutes. If you've seen a problem like that before, you
could get an answer out on the whiteboard in 5-10 minutes (external merge sort is
incredibly easy to analyze and do without errors) and spend the rest of the
interview discussing more general topics around scalability and warehouse scale
data.
That's why prep is important -- it makes sure you're exposed to topics that might
come up. These interview topics aren't meant to be hard, nor to take you near the
full amount of time to solve (all of the problems in that Google post could be done
in 10 minutes by a good candidate). They're to evaluate your comfort with a set of
algorithms or general problem domains. And the only way to get comfortable with
something is to read up on it and practice.
permalink embed parent

[] alienz225 3 points 2 years ago

in that big thread where a Google employee

Which big thread? Link please?


permalink embed parent

[] Quinnjaminn Software Engineer

5 points 2 years ago

This one. I also added it into my original post.


permalink embed parent

[] songhyeondeok 1 point 2 years ago*

Sure but they're not trying to test your knowledge, they're trying trying to test
your general coding ability. They will completely understand if you don't know
external merge sort, and they'll be even more impressed if you come up with a
solution on your own. Interviewers are actively trying to minimize the effect
that studying could play on an interview, they want to determine how good of a
coder you are, not how good you are at studying.

edit: btw there's a faster (expected) algorithm for that task than the one you
described as long as the data set is reasonable. You use a hash, and record
only if there's a collision in the bucket, not the actual string. During this run the
expected number of collisions where the string don't actually match is small,
but there will be some. Then after that pass, you do another where you hash
completely, but only if the hash of the string had a collision in the previous run,
and if there was a collision you remove the string. If you end up with too many
collisions the first pass to fit the full data in memory, you just repeat with a
different hash function. The probability that the data will always be too large to
store this way is incredibly small. The run time of this algorithm is O(n), and it
completes with very minimal disk reads.
This two step process is not even necessary if the strings are within the set of
English words, you can just do a single pass in that case. Solutions like these
that aren't just regurgitating what you learned in class are likely more
interesting to the interviewer, and you won't be penalized at all.
permalink embed parent

[] Quinnjaminn Software Engineer

1 point 2 years ago

Yeah, I think the point I was trying to get across was that prep is really
useful -- until a point. If you don't know your fundamental algorithms/data
structures, then that prep will make a world of difference. I don't personally
prep more than an hour for interviews, but that's because I feel like the
"prep" was taken care of by my education and experience. The advice I
gave was more geared towards people without as strong of a background.

It really comes down to that difficulty of gauging a software engineer's skill


in less than an hour. You want to test for fundamental study/knowledge,
without managing to give a huge advantage to people with specific domain
knowledge. With google, I don't think basic external algorithms go beyond
expected general knowledge, but it likely is for most companies. I had a
discussion with my team lead on interviews recently, and the difficulty of
judging skill is a real problem. We personally use the problem more as a
screen, where you can kind of gauge [bad | ok | good], but not much more.
Soft questions and subtle details really set aside the best.

As for recursive hashing, it's a definitely the ideal solution -- it's also what is
done within database systems for that kind of request. You can pull some

clever tricks to keep track of metadata for stuff like group-bys, and it's overall
the best solution. However, I could never implement external recursive
hashing in an interview, but I could easily do external merge sort and mention
hashing.

I chose sorting as a reasonable solution because, while it's O(nlogn) instead of


O(n) in terms of computational operations, it's easy to show that it has the
same bound on memory operations as hashing (at least, the one I learned).
Merge sort has a lower constant as well. Since memory operations are such a
dominating factor, I would argue that merge sort will be sufficient unless such
an elimination of duplicates is a core, commonly repeated operation.
permalink embed parent

[] dandr01d [S] 15 points 2 years ago

If you can wing a big 4 interview and pass, then this guide isn't for you. This is
more for intern/SDE1 phone screen type questions.
permalink embed parent

[] XyphonX 1 point 2 years ago

Thanks a lot!

permalink embed

[] brozzart 1 point 2 years ago

Appreciate this list! Thanks


permalink embed

[] No_Disassemble_J5 1 point 2 years ago

I have a lot to re-read and go over again. Thanks for this


permalink embed

[] frycicle 1 point 2 years ago

Just buy Cracking the Code Interview or Programming Interviews Exposed. Best books
on this stuff I've read.
permalink embed

[] Librish 1 point 2 years ago

Very useful stuff!


permalink embed

[] glug_glug_glug 1 point 2 years ago

Saving

permalink embed

[] obj7777 1 point 2 years ago

Nice.

permalink embed

[] TraderJoesSeaSalt 1 point 2 years ago

Right, these get you through the first 10 minutes of the tech questions. It will go
something like this:
Write a function to tell if a string is a palindrome.

Write a function to turn a string into a palindrome using the fewest number of insertions.
Your answer took exponential time, how do we speed it up?
Now you are on a multicore machine.

And your string doesn't fit into memory.

And now you are on a cluster of different machines.


And one of those machines went down.
permalink embed

[] djn808 4 points 2 years ago

Welp, I'm boned.

permalink embed parent

[] [deleted] 1 point 2 years ago

The shortest palindrome in a string is the empty string.


Every tree has a subtree consisting of 0 nodes.
permalink embed

[] farrukhghaffar 1 point 2 years ago

Great list to get me started..


permalink embed

[] BonafideZulu 1 point 1 year ago

Thanks, man. Greatly appreciated. Commenting for future reference.


permalink embed

[+] [deleted] 2 years ago (1 child)

[] darkquanta42 1 point 2 years ago

Thank you! This is awesome for practice.


permalink embed

[] totes_meta_bot -1 points 2 years ago*

This thread has been linked to from elsewhere on reddit.

[/r/orchestratedchaos] A nice comprehensive list of programming interview


questions for the Big 4

[/r/Programming_Interview] Compiled list of coding interview questions (Xpost


r/cscareerquestions)

I am a bot. Comments? Complaints? Send them to my inbox!


permalink embed

[] pds12345 0 points 2 years ago

Applying for internships! Thanks much!


permalink embed

[] DHarry 0 points 2 years ago

I wish I had known that interviewers would grill you on this shit before I went into CS..
permalink embed

[] [deleted] -2 points 2 years ago*

Very nice!. Here's another one:

How to find pairs that equal to a specific sum in an array

permalink embed

about

blog
about
source code
advertise
jobs

help

site rules
FAQ
wiki
reddiquette
transparency
contact us

apps & tools

Reddit for iPhone


Reddit for
Android
mobile website
buttons

<3

reddit gold
redditgifts

Use of this site constitutes acceptance of our User Agreement and Privacy Policy (updated). 2016 reddit inc. All rights reserved.
REDDIT and the ALIEN Logo are registered trademarks of reddit inc.
Advertise - technology

Das könnte Ihnen auch gefallen