Tech IndustryJan 17, 2020
Qualcommdynasty001

looking to learn after a disastrous interview onsite

background : C/CPP Modem SW eng got asked a question at my onsite say you have an array of numbers (assume size 10 for now) , find the minimum number which occurs atleast 2 times. i was asked to write code. i iterated over the array and created a frequency map (hashmap of number and their count) . then iterate over the map and for every (key,value) pair such that if the value is >= 2 , i will throw it into a min_heap (priority_queue ) . the top element of the min_heap will give me my answer. was this the correct approach ? i was really nervous at this point . the interviewer was ok with it and asked me to run my code against a sample (which i had already done ) now he asked me to scale my code 1 . what changes will i make to my code to make sure millions of servers can access the data and get the minimum value. which is turn can provide output to another millions of servers. 2. if there are multiple ppl trying to read and write at same time, make changes in code to handle that. for #1 . i drew a blank. (i had learnt system design on how to scale but dont know what code can i write ) for #2 i said it was a concurrency issue and that i would protect data access using a mutex . He said me what is a mutex !? . i explained that to him. He was not satisfied. He ended the interview saying “you need to think of scale when writing code” . And of course i got a reject. i am looking to find about ways to solving such questions. how would you respond ? it would be great to get a list of questions which i can prepare with for such issues on future also got asked “LFU cache” . Talked thru the design . interviewer asked “have you seen this question before” i said not exactly the same but have done a ton of similar questions for practise as said in the recruiter prep material. was i wrong in saying that ? please note i had only 15 mins to think of an answer and write code because the other 30 mins were taken by mandatory behavioral questions. tc : 120k 5 yoe

Add a comment
Google bighead2 Jan 17, 2020

Iterate over the array with a Set. Also a variable for min so far. If a number is already in the set, update the min if needed

Qualcomm dynasty001 OP Jan 17, 2020

Thanks. Understood your solution. My solution woukd consume a lot more memory. Thanks a lot.

Google bighead2 Jan 17, 2020

Cool. For follow up questions, I don't know whether a Set is threadsafe, and all that. I only know things you can learn on Leetcode.

Qualcomm dynasty001 OP Jan 17, 2020

Agree. So any ideas how to make the code scalable ? Or was the heap the limiting issue ? I talked thru generic scalable systems but he kept asking please inplement it in code and i was blank

Facebook tAGO84 Jan 17, 2020

Then implement it in code, my friend.

Qualcomm dynasty001 OP Jan 17, 2020

I dont know how to implement a scalable design on code. Can you please provide pointers ? I only practised Leetcode and educative.io grokking.

Marvell kuuD23 Jan 17, 2020

#1: When millions of servers are involved, serve them from the cache where you maintain current min. Avoid going over the array over and over again. Only when the input has changed, you need to run the program again to find the new min. Again, if the new element(s) add to the end of the array are greater then current min then what? if they are smaller then what? do you poll for data in array to change or receive an event. I believe those may have helped. Also what to do when something is removed. 2: Ask how time critical the data is, if writes are important then writers get priority. But again, since you're serving the data from cache so multiple readers may not exist at all which means only writers need to be exclusive in which case whether you spin on lock or suspend. Since there is a chance of min getting changed so the min value needs to be accessed within the lock but thats a question I'd ask whether millions of servers are latency critical or whether they can live with stale data.

Microsoft MP3v2 Jan 17, 2020

I feel like you just uploaded knowledge into my brain. Thanks a lot for this!

Oz Management swusr Jan 17, 2020

Which company?

Qualcomm dynasty001 OP Jan 17, 2020

Amzn

Nike softwareng Jan 18, 2020

What level at amazon?

Lowe’s kBLA63 Jan 17, 2020

lol this wasn’t disastrous, these are hard questions that’ll mess anyone up, let alone a hw engineer. I’ve had an on-site systems design question I couldn’t even solve the first step of lol, then I started freaking out and saying random stuff about load balancing lololol oh god, didn’t get the job And I’m actually not sure how to answer the last question, in ctci it says to let your interviewer know, however I’ve seen a lot of blinders who don’t recommend letting them know