>be me >live in a ghetto >be a CS major at the best Mexican University (#113 worldwide) >spend 3 hours on a bus just to attend lectures >professor gives some lecture notes >notes include a pajet tier quicksort implementation (see pic) >apply to facebook as a joke >got an interview for a summer internship >interviewer has a thick Asian accent >I have a thick Mexican accent >connection freezes up every 30 seconds >got asked this question: leetcode.com/problems/intersection-of-two-linked-lists/ >immediately think of a O(n) space O(n) time solution >i say nothing, wanted to solve it in O(n) space O(1) time >i can’t >after 20 minutes the interviewer thinks I’m stupid and gives me the answer >got rejected >a girl in my class who barely codes got an offer
I fucked up my only opportunity to get out of this shithole
O(n) time O(n) space : Save the longest list in a set, then iterate over the shortest list an check the node is in the set. O(n) time O(1) space: Make both list the same length and compare both list at the same time.
Isaac Turner
*and check if the node is in the set
Luke Campbell
How do I learn to big O? Read it in a program, and understand what () means.
James Barnes
thumb rule: O(1) the answer takes the same time no matter how big the input is O(log n) Google:"binary search" O(n) 1 for loop from 0 to n O(n log n) 1 for loop from 0 to n and on each iteration computes a log n operation O(n^2) 2 nested for loops from 0 to n O(n^3) 3 nested for loops from 0 to n O(n!) compute all permutations O(2^n) compute all combinations
Liam Bell
Lots of other companies out there. In these types of interviews you want to say what you're thinking out loud all the time. Don't go silent for a long time or they'll think you don't know what you're doing. Also pick up a how to do coding interviews book or Google that stuff.
Beaner here, for interviews you need to show the interviewer your thought process. Start with a complex brute force solution and then optimize as much as you can. Talk about your thoughts while you do it they like that. Don't apply for big companies in Mexico, they know we are cheap as fuck and get away with paying 1/3 of what you are worth (specially Oracle) so go seek some startups there are a lot in Mexico City or GDL, an other option is to freelance for USA, Canada or European companies (work remotely).
The uni you come from and your title mean shit , we are shit country and our universities have shity courses almost on everything IT related, only worth studying medicine here. If you didn't get that memo when you got in then it's your own retardation's fault.
>>i say nothing This is where you lost m8. In those interviews, ANY solution gives you much better grades than nothing. Should have explained the o(n)/o(n) solution and immediately followed up with >this can be done in constant space but I need to think and only then you can be silent. Likely that the interviewer will tell you to not bother at this point and ask a different question.
My guess is pre-process both linked lists to find their length, then traverse the longer of the two until they're both the same length, comparing the *next of each node from that point onward.
Charles Gutierrez
yes I was dumb and thought ot it's like the tortuise and hare one nd went downt hat path
Kayden Phillips
Here they pay programmers less than a half of what companies pay in other countries for the same amount of experience. I'm discarding getting a programming job here, I'm aiming towards sys admin or some shit
>i say nothing never do this in any interview ever, jesus fuck. The only time you shouldn't be talking is when the interviewer is talking.
Ayden Thomas
#include
int partition(int*, int, int);
void quicksort(int *a, int len) { if(!a || len
James Fisher
I think the do nothing parts were in fact doing two things, both an assertion and a skip ahead (already sorted check).
Justin Perez
> Make both list the same length and compare both list at the same time. I don't think that'll work. If you could go backwards then you could start at the end of both and find a node that was different, but it's a singly linked list
Logan Miller
Wouldnt this just be solved by reversing the lists(access the last element if that operation is provided) and iterating backwards until the nodes are different?
William Perry
You're retarded, you can't solve it in O(1) time. This is a simple iteration problem.
how do you expect to solve any problem that involves iterating over linked lists in O(1) time? you are an idiot
Luke Adams
Yeah but how do you figure out wherever it's O(n log n) or O(n^2) etcetera? OP said, "immediately think of a O(n) space O(n) time solution" but I don't know how to do that.
Ryan Hall
You are literally replying to the post that answers your question
Lucas Thomas
>wanted to solve it in O(n) space O(1) time >O(n) space O(1) time
>Be me >Going to school and working full time (work before you get to college so you have interviews and work experience already) >Already know IT shit, but needed a degree for foot in door >Know everything being taught, still listen in case I missed something, did all work required >Studied even more than I needed to >Class has to do project the whole day, classes are 3 hours. Done in 20 minutes. >Teacher checked my shit and was impressed, had me help half the side of the classroom while he helped the other Found out later I got a job offer because of that teacher. Got the job and stayed with them for 8 years. They have 4 people before me that never lasted longer than 3 months. Advice: Work/study harder than required. It will be the difference between a career or just a job.
Easton Collins
This doesn't sort the random numbers correctly, there is something wrong with it.
Ethan Parker
isnt iteration O(n) ?
Zachary Miller
Hoare is probably reading this thread and laughing at all of you right now.
Pinches morros de la unam, se la dan de muy vergas y a la hora de la hora se cagan pa dentro
Henry Martin
I think he meant the UNAM
Asher Edwards
>3 hour bus ride and no hope for the future He's either at UNAM or IPN You're supposed to come up with a solution as soon as possible and then tell the interviewer you might find better solution, employers, especially enterprise quality ones, only care about speed FB isn't so enterprise but for actual quality stuff they employ PhDs and people with plenty of experience Unless you have divine intellect at programing yeah
Luis White
>Things that never happened that Jow Forums wishes did
Asher Cook
that was a fun question, it made me think for a bit, but did it in O(2n) which is O(n) so mission accomplished. now post MORE I'm bored
Here's my attempt >start at end of both lists >if the last nodes aren't the same, they don't intersect >if they are the same, go in reverse down the lists, return the node following the first pair that aren't the same O(n) time, O(1) space (keeping track of the node you might need to return)
Jaxson Gomez
Hi econ 100a bro
Angel Green
>Python >Google Good going user.
Tyler Ward
Welcome to normalcy Though family connections beat people skills here Basically, you're fucked and can't learn to avoid the fuckery
This is why high IQ people stay NEETs
Colton Nguyen
going backwards in a SLL. ouch.
Hudson Johnson
> He thinks UNAM is a good University for CS
No wonder you fucked up. ESCOM and ITESM are the only decent CS programs in the country