labsurde-life / english

Apache License 2.0
0 stars 0 forks source link

Studying "Coding Interviews Be Like" #15

Open hyunsik-yoon opened 1 year ago

hyunsik-yoon commented 1 year ago

https://www.youtube.com/watch?v=kVgy1GSDHG8

hyunsik-yoon commented 1 year ago

part 1.

what is going on here.

hey nick, studying for interview?

yeah. i am but i am really nervous. and i mean, i can't eve invert a binary tree or reverse a linked list.

wait. when's your interview? i think it's in like five minutes..?

you know what? you're probably gonna fail. but if you ever get stuck, just throw hashmap at the problem.

ok. it's time.

hey, nick. i am nick with k. i am a senior software engineer here at facezon. I am just gonna send over a ~code to pat~ coder pad and we can get started.

yeap.

so, here the problem. give an array of interger nums and integer target, return indices of two numbers such that they add up to target. you can just assume that there is always a solution.

what an easy problem. i did that last night. but i am gonna protend that i've never seen this before.

hmm. interesting. i guess my initial approach to use is two for loops, and then iterate through the array, checking whether the sum of the current number each of the current number adds up to the target.

yeap. that sounds like a good start. do you want to code it up?

yeah, sure. no problem. i'll start coding it up right now.

and then.. in the event that there are no solution, we can just throw an error. yeah. that should work. its time complexity is O(n^2) because for each element, we're looping through the rest of the array to find it's complement, which takes O(n) time. And. also the space complexity is O(n).

hyunsik-yoon commented 1 year ago

https://youtu.be/kVgy1GSDHG8?t=125