Want to give it a shot?? Sign up with us to make sure your upcoming interviews are the best they can be by practicing with our experienced engineers. interviewing.io/signup?.com&
Inerviewer: Choose any language you want. Me: Ok, python. Inerviewer: Ok great. Lets Go. Middle of first problem.... Interviewer: Forgot to mention, you cant use any of pythons features. Me: Can I change to C?
@@coolkatmehrfth Im pretty sure people who worked with that... pretty much had no life to begin with... you cant die when you don't even have a life in the first place :)))
I really dont think these types of technical challenges find good developers, I think they just find developers who either know the syntax of a language in depth or happen to have done the exact problem before. Taking the problem at 9:05 as an example, I dont know how to do this in Javascript syntax (I work in Javascript every day). However I know what I need to do, and googling it gave me a 2 line answer in less than 10 seconds. So I would have failed this test, but would have completed it in under 10 seconds in a real work environment. I dont think this makes me a bad developer. I think much better technical interviews are to present the user with an already working bit of code (or not) and get them to expand on it, or fix it, using what is already there.
Was looking for this comment. + The fact that they are talking about complexity and time but IRL it depends on how the language is interpreted by the machine. If you're not working on complex algorithms, you never do this.
Agreed. The skill that the interviewer testing here is not just dev skills, but also computer science principles, which based on which company hires you, treats as important to churning out code. For IT services based company, which are focused on realizing business use cases, time and space complexity might not matter as much as code maintainability, code refactoring etc. But it would matter for product companies like Google, Amazon, where every microsecond and byte saved makes a world of difference.
exactly. That is my exact perspective. You are just catching a developer who failed that question before, so they remember how to solve that particular problem the next time it gets asked.
This was probably my favorite interviewer from the ones I've seen. Clearly experienced, not bothering to write long problems on screen, or setting the parameters of the interview and just letting it flow, be more human. You don't need to go all Voight Kampff on someone to get a good sense of their skills.
Yeah exactly dude, it's more of a test to understand if the guy who's writing the reverse a string answer didn't just memorize the thing in X language and wrote it up and not knows what he is doing, much better to ask explanations of simple problems and why the answer you think is the right one is the right one. Good engineers are not ones that mug up but ones who actually can create shit from pre existing shit and somehow better it up !
If you've ever hired a developer that didn't know how to problem solve and use very simple language constructs you know the value of these tests. Maybe they are a little academic but most times they are trying to understand your problem solving ability not your knowledge of obscure language concepts. We hired a guy that had an amazing CV that looked like he could've invented Java himself when we got him into our department he was a nightmare and had almost no concept of how to problem solve in code. It was a disaster and the company that hired him was a charity that felt too bad to fire him otherwise he would've lost his visa.
I have an issue with this type of interview. High performance "reverse" algorithms are pretty much only useful for working with really massive datasets, like DNA/RNA. The real issues that businesses face have to do with solving business problems. Reversing a string is not a business problem. Anyone can look up the "current, most optimal way" to solve your sorting problem, reverse problem, etc. It takes an engineering mindset to architect a solution to a business problem, though... which is a totally different skillset and what pretty much every company actually desires (outside of research and game engine development). I have had many interviews and given many interviews where wrapping your head around a real life problem gives far more information about the ability to engineer software. "Say you have 50 requests coming in every second to your online shopping product catalog. How do you best serve that data to your customers if that data is sitting in your database?" Answer: 1. "Pull the active product data into a cache, where the data is easy to sort and categorize for the filters the customer selects. This way, the customers are searching in-memory data." 2. "Load balance customer requests over several web servers so wait times are shorter. Ensure your web servers have available resources (bandwidth, RAM, etc) and your database server(s) has a reasonable number of connections available and that each query returns the smallest dataset." 3. "Optimize filtering to reduce the product set as quickly as possible. Smaller datasets are far more performant. This might limit the number of products a customer sees at once (say, the first 20 results)." "Assume your customers have to upload numerous high quality (i.e. large) images to your site. How would you handle this?" Answer: 1. "Bandwidth will be an issue. Many areas do not have gigabit fiber. Colocation can have anywhere from 20-100 mbps on a standard connection. If you have 12 Megapixel images, each one is roughly 12 Megabytes (or more, if they have higher color bit rates). 12 MB * 8 bits/byte = 98 Mbits. So a single image can max out the available download pipeline of a small operation, if only for 1 second. In reality, customer upload speeds will vary wildly. The images will need RAID storage, for performance and safety (backup)." 2. "If cost is not too big of an issue, consider cloud storage. This will alleviate issues with load balancing, bandwidth, storage space, and image backups. It will also provide high availability and allow your business to expand to other global regions, quickly. This may take the form of a Kubernetes cluster." I don't expect a candidate to know "everything". I expect them to give it their best shot. Then I might have them draw a diagram. Or write out a SQL query. Or pseudo-code a small piece of their response. Do they focus on hardware solutions? Do they focus on database solutions? Do they focus on software solutions? Do they understand current tech trends? Are they a capable problem solver? Do they think through the solution? Do they get frustrated? Do they ask for help? Do they throw out ideas? Do they eliminate bad ideas? Do they ultimately solve the problem? Do they make excuses? Do they enjoy the process? Do they get completely stuck? Did they lie about their skillset on their resume? Would you enjoy having this person on your team? Would they bring new approaches/skills to the table? To me, memorizing algorithms just tells me that they studied like it was a college test. I have worked with DNA, so I know that performance is important, but it isn't great for a job interview question. It's also one Google search away. Looking at a real problem requires multiple approaches and an accumulation of knowledge (the thing you need humans for). I've had the pleasure of working with, and learning from, very talented people. It's difficult, in my mind, to find those people with this type of approach.
its difficult to find those people because they are leading a business. If you are capable of thinking like this you won't bother working for someone else.
@@QuiiKSyyntax I don't agree. Having business skills is completely different. Knowing when to get a lawyer involved, contract negotiations, taxes & expense management, hiring, sales, finding new clients... these are all way outside most technical people's wheelhouse. I think most technical people don't want to deal with the business, so they work with companies that allow them to do what they do best. I've met a lot of really talented developers, none of whom run a company. Are they smart enough to run a company? Probably.
Matthew those business skills won’t get you anywhere when trying to build your own business without beeing an expert at something. There are two options tho, either you make your business knowledge a business itself or you have the money to hire the people you need to do stuff you can’t. While people with problem solver attitude and beeing an expert at something can all be great business leaders, because not figuring something out is not an option.
@@redwoodenjoyer Biggest application is in cryptography IMO. It's very fast to compute, easy to understand, commutative and associative ! Basic example of a XOR cypher : en.wikipedia.org/wiki/XOR_cipher
blake XORs largest application is actually probably for a full-adder implemented in hardware honestly. Total # of XORs used for that purpose has to be in billions/trillions at this point
Yeah pretty dumb stuff these interviews... always the same textbook question with no real application. These engineers are stuck is the 80s and don't want to grow out of it.
For the one-liner programmers this would be solution for the technical questions # Reverse string function def reverse_string(input_str): return "".join(str[::-1]) # Find missing element in the list def find_missing_element(list_a, list_b): return [x for x in list_a if x not in list_b] regarding to the variables names in the find_missing_element function, I think it need to be clear which one is the full list and which is the partial list. A side note, the interviewer said that he would use "str" as a variable name for the reverse function but actually I am not fan of using just "str" because it's a python built-in function and it might cause a syntax error.
all the while he was thinking "please don't make me implement heap sort please don't make me implement heap sort." just one of those things where you know you can probably do it if you had to, but you just never want to.
Yes, so it's basically can be done in O(n) time and O(1) space! I was also thinking about why didn't find the solution. Because when the interviewer said "only one element missing" then my first thought was missing element = sum(full)-sum(partial)
For the second problem: Simple swift solution which just sums up each array and returns the difference which is the missing element. O(N) time O(1) space func findMissing(_ fullArray: [Int], _ partialArray: [Int]) -> Int { let sumOfFull = fullArray.reduce(0, +) let sumOfPartial = partialArray.reduce(0, +) return sumOfFull - sumOfPartial } If there are multiple items missing.. we just make a set from the partial array and iterate through the full array and keep track of what items aren't contained in the set: O(N) Time & Space var set: Set = [] var missingNums: [Int] = [] for num in partialArray { set.insert(num) } for num in fullArray { if set.contains(num) == false { missingNums.append(num) } } return missingNums
I don't know. Never worked in a company that cares about time complexity. Unless you are doing low level, high-speed services, it really doesn't matter. What matters more is readability and maintainability.
Really? I think these interviews are exaggerated but time and space complexity knowledge was important even for me who only did internships and haven't graduated yet.
@@windskm In the general industry, it doesn't matter. Everything is based on how quickly you can get a product to market. Firms are more than happy for you to use a couple more E2 instances to handle the load and get the feature 50% faster to the users because you used a pre-defined logic. Another good example is immutable functional programming, every "map, flatmap, filter etc" will create a new collection or monad. It's wasteful cpu-timewise (and memory wise). But it's more deterministic, easier to read and faster to get to the market. Even in data science, rarely who would want you to manually rewrite neural nets from scratch if you can simply wire them with pre-written modules by Google. Now, there are exceptions (as I mentioned). The core teams. They must care about deep level dynamics. If your team develops the core frameworks that will be used by other teams, every small delay in your core will impact their end products.
@@artursvancans9702 ahhh gotcha. Yes, I think that makes senses when developers don't need to care about server bills. Still, if there's a clear O(n) solution to a problem than why do an O(n**2)? I think that's why companies who run a lot of their infrastructure (google, mcsft, facebook) want every single one of their SWE engineers to know this, even if they are front-end, back-end, dev-ops, low-level or whatever.
@@ItsMeChillTyme It always depends on the job culture. I have seen some contractors trying to keep everything as secretive as possible. Mostly happens in corporate environments. However, usually you work in a team, your features are PR'ed or worked in pairs. The convoluted code will just simply not get to the prod. Even if you work solo, in most cases your tech lead or head of tech will follow Bus Factor, that will make sure at least 2 other people can replace you at any point. TLDR - It happens. But in shitty companies.
To all the people who are commenting that these are real world problems or they wont be used in development, i am sorry to inform you that this interview isn't intended to check your programming skill to glue API or other stuff. The main aim of these type of interviews is to check the approach a person uses to get to the solution, if he/she gets stuck at some point, then what is their attitude towards that difficulty. Real world problems dont get solved during the one hour or half hour interview. They require people who built solutions to a problem, there is nothing special about people who glue API together. API is based on work did by engineers who are capable to solve such problems.
For most jobs worth wanting, more important than big O is *being cool*. Being friendly, easy to chat with, and interested in the person you’re talking to.
It's kind of fundamental stuff as far as programming goes. You can program without knowing this, but unless you have a basic understanding of time & space complexity, you can accidentally write code that is suuuper slow.
@@kristupasantanavicius9093 in a language like python, strings are immutable, so you create a new string through copying. Copying a string with m characters will take m operations. If you perform the copy operation in a loop, from 1 to n, you get 1 + 2 + 3 + ... + n-1 + n. You might know that this can also be expressed as n*(n+1) / 2. Expanded, this becomes n^2 / 2 + n / 2. We aren't interested in coefficients, and only the most significant term, so this all becomes O(n^2). In practice, copying a string with m characters might only take m/8 instructions (copying a word at a time, instead of a byte at a time). However, if you plug this into the above, you will still get O(n^2), because the coefficients are discarded. Note that either way, this copy operation is O(n). Time complexity is compositable; if you are combining 2 algorithms, or using an algorithm in a loop, you can use the time complexities of the individual algorithms to find the overall time complexity. Hope this all makes sense
@@mardvorak2 well, I learned the concept in my data structures and algorithms class in college. I bet you could find a free course online that covers this. Otherwise, I dunno, the internet has everything nowadays
Great interview, some commentators are obviously extremely infatuated with themselves and do not understand what stress is until they are at an interview themselves, but this guy did awesome. Really cool I greatly enjoyed this and shows I have some common thinking.
Nobody Cares Serialisation and deserialization is essentially taking a tree data structure and removing the values in a certain order (tree shifting each time) and putting it into a new tree. The only difference compared to a linear data structure is the order of removal and order of placement instead of FIFO
@@pointinpolyhedron yes that's kind of correct it's just you have to keep track of where all the null values are and how many branches there are for each node before you insert into JSON. That's the tricky part
By the way, mind you this is just 1st round. It's not like he is going to get an offer by reversing a string. Then you have to do multiple technical rounds consisting of design and architecture related questions. Nowadays they test EVERYTHING. From developer common sense to architecture of the system. After 5-6 rounds of this you get a result which is again very low for such companies.
The questions are really simple: #Question 1 def reverse(s): return s[::-1] s = "abc" print(reverse(s)) #"cba" #Question 2 def findLast(l1,l2): for i in l1: if i not in l2: return i
I had one of these "blackboard" interviews with Indeed. Honestly, it did not prove that I was a good Python developer or not. I was more nervous than anything while doing it.
1. return x[::-1] 2. Just do binary xor for all numbers in both arrays, the result will be equal to the missing number. O(n) time, O(1) space. Like: return functools.reduce(itertools.chain(arr1, arr2), operator.xor)
9:20 if the arrays are numeric I would just add up the values to get the missing one by subtraction. But that is very limited. edit: Ah ok, it is mentioned at 19:30
bruh that's like 2nd grade problem. just to Return list(x for x in full_set if x not in partial_set).That would also work if there are more than 1 element missing.
def StringReverse(astring): astring = str(astring) reversed_string = astring[::-1] return reversed_string This is a much easier way of writing a function which reverses strings
So interesting that people often assume atting charscto a string is O(1) operation. This must have been his thought Wenn claiming it is linear in time. I really loved the xor approach (:
Python scripters are very poor. The rates are extremely low. Due to low learning curve and low intelligence required to learn it. But this guy still don’t know basic stuff.
@@gilfhunter42069 hehe yes. actually, data scientists use py -- high mathematics and stats or genetics - very high skillset, very high pay. but that is probably 5% of all the jobs. the rest is like every other language - an average (of programmers) person can do it. So especially for this vid, my statement is most likely right on the money.
@@johnmadsen37 Well, I don't know. As long as you need a degree for the job, the pay of a python software engineer (which is usually connected to machine learning, data science or simillar fields, because why else would you want to use python in enterprise situations) is high
Neither of you were right about which sorting algorithm Python uses. It's not a modified quicksort, but a modified mergesort that uses insertion sort once the sublists get small enough for improved cache behavior called "Timsort" en.wikipedia.org/wiki/Timsort
Idk how effective these tests are. I mean yes, it is good to know the syntax of a certain language as in-depth as you can. And you should be able to think about a problem given to you and think of multiple ways to get to the solution. But then again, going to stack overflow can get you your solution in a matter of seconds. What matters most on the job is your resourcefulness and persistence. You can't really determine that about a person just from one interview.
the interviewer said that he would name the string str at 26:06 but that no one would actually do that since str() is a built in function in python lol
@@justarandomcitizen210 i was wrong, it actually does compile but it's just not good practice. sometimes it works but nobody who codes in python would do that since it's a native function and this can lead to many errors/unintended consequences. this is okay in java, C, and many other languages but not python. just a nit picky detail
@@sliderBro No new allocation, it's (O)n, because it's only using the step argument of string slicing. It's the equivalent of starting at &string + sizeof(string) and decrementing the pointer by 1 until 0 in C. Pro Tip: A strong understanding of C really helps out in python, as the types in python are usually more complex object types from C (list, dict, etc).
@@mattymattffs dude. That immediately went through my head What the hell was the point of that? And im not quite sure but appending it to the end of the list would make that O(n) so better than his concatenation
Technical interview: loosely translated, an hour of ignoring the fact modern languages handle these operations for us so we can make ourselves feel clever.
Interviewer: You need to implement a function to reverse a string, how would you do it? Bad answer: Explain how to write a program to reverse a string. Good answer: Use the built-in string libraries reverse function every language has. Interviewer: You need to divide numbers but your dog ate your / key, what do you do? Bad answer: Explain how to divide using bitwise operations and subtraction. Good answer: Get a new keyboard. Interviewer: They can't afford a new keyboard. Good answer: Quit and get a new job, this place is going bankrupt.
The functions are very easy but then the interviewer throws in questions like what are the time and space complexities of sorting algorithms. That's going to catch anyone off-guard, especially junior developers.
The solution for the second problem can be obtained better than O(N) : Difference between sum(original set) - sum(input set). This would work as the interviewer made it clear only one element would be missing (regardless of if elements were positive/negative integers)
Really not hard unless you wanna be specific like setx - sety is actually O(len(setx)) avg case in Py but this guy wasnt expected to know that either. Anything that does one thing is O(1), a loop is O(n), except for loops where you can break or otherwise not process all elements those are log n. And nested loops are multiplied [2 nested for loops would be O(n.n) aka O(n²), non nested loops would be O(n+n)]. Also good to do in interview if you're confident is ask if they want to know avg or worst case
Couldn't hear very well, but I tried following along with the results: def reverse(x): return x[-1::-1] i = reverse('Hello!') print(i) """ """ # 08:14 def findMissing(x, y): for i in x: if i not in y: return i x = [4, 12, 9, 5, 6] y = [4, 12, 9, 6] z = findMissing(x, y) print(z) """
Can't you reverse a string in python by creating a slice that starts at the ending position and moves backwards? def reverse(x): return x[::-1] I think there is no faster way to reverse a string in python but this is still O(n) time complexity.
Those are the worst interviews. I would rather want to see reverse python built-in function rather than that overly convoluted for-loop solution. A better tech interview would be them talking about higher-level and architectural problems.
You are both missing the point. He is testing his problem solving skills and his thought process, that's why on many interviews I hear "please think out loud". Whether the problem he solves is useful doesn't matter at all.
NDD He’s asking for specific computer science problems to solve. This problems have hardly any application in real life. You could be dismissing real problem solvers for folks that read a Wikipedia article before the interview.
Three solutions in 10 minutes for find_missing #use set Time O(n), Space O(n) def find_missing1(arr1, arr2): sa = set(arr2) for a in arr1: if a not in sa: return a return None print(find_missing1([1,2,3,4,5],[5,4,3,1])) #use math sum, Time O(n), Space O(1) def find_missing2(arr1, arr2): return sum(arr1) - sum(arr2) print(find_missing2([1,2,3,4,5],[5,4,3,1])) #use bit operation, Time O(n), Space O(1) def find_missing3(arr1, arr2): ans = 0 for a in arr1: ans ^= a for a in arr2: ans ^= a return ans print(find_missing3([1,2,3,4,5],[5,4,3,1]))
Kinda tired right now, but I think he could find the missing item in just O(n) with something like this: function findMissing(fullArray, partialArray) { let index = 0, fullArraySum = 0, partialArraySum = 0; // Using while instead of for because we don't want to do an extra iteration // for finding the fullArray length. while (fullArray[index] !== undefined) { fullArraySum += fullArray[index]; partialArraySum += partialArray[index] ?? 0; index++; } return fullArraySum - partialArraySum; } findMissing([4, 12, 9, 5, 6], [4, 9, 12, 6]); // 5
Why did they never actually run any of the code? Like they never called any of the functions... I didn't watch the whole thing to see if there were any clear mistakes, but they kept saying 'it works' when they really only checked if the interpreter would syntactically accept that code...
Matt Billenstein What did you think was happening everytime he said “let’s give it a quick run” followed by long silence, followed by him saying “it works”? Here’s the last one of about five or so times it happened: 23:10 He was running the code on his end, probably even copied it directly out of the interview interface and onto a separate environment just so he could see the results and say whatever he wanted to the interviewee (maybe even lie or mislead them in the results to see if they stick by and defend their code or roll over and assume it’s wrong even when it isn’t) I really do hope that most prospective technical employees know that just because you don’t see something on screen doesn’t mean that it isn’t happening on the other end. Otherwise all our future backend developers will start to leave for GUI and front end development not realizing there’s more that makes their programs work than what they actually see. 23:10
Matt Billenstein what do I think is happening? Exactly what I stated is happening, the code IS indeed being run and it confirms it on screen every time it runs on the timestamp of “extenuated at”. Look at the time value changing above the part that says “Mammoth Avenger ran 29 lines of Python.” And notice how every time he runs it the time stamp changes it to confirm he ran it again at the most recent time? So “what do I think happened”? I think Mammoth Avenger’s code was RUN several times by him and/or the interviewer, because it literally says it was and even confirms it every time above “ran code” changes (and I recall it changing at least five times)
@@kieranhorganmallow Can you show me any link or documentation that says it is quicksort not mergesort? Any article could be wrong so lets go straight to the source. github.com/python/cpython/blob/master/Objects/listobject.c#L1881 This is the code that performs the merge operation on a list sort. github.com/python/cpython/blob/master/Objects/listsort.txt You can also take a look at this link which describes and compares the performance of the sort
@@kieranhorganmallow Also, I just noticed you said quicksort is faster on average than merge sort, quicksort has the same speed as mergesort both on average and in the best case. The advantage of QS over MS is that QS uses O(log(n)) space complexity where MS needs O(n)
for the problem where we find the missing item in an array, here's the logic i could come up with using javascript. i loop through the second array (using a typical for loop of course), so i check if an item from the second array is present in the first array. If it is, i'll delete it from the first array. I repeat this process until only the missing items are left in the first array. Then i just return it is as "THE MISSING ITEMS!!!".
Can somebody explain to me the time complexity of string reverse? What do they mean Big O on N? O(n)? Then the interviewee says "its another N"?? You can't have 2N, because time complexity is not measuring the time taken, but rather the time taken relative to the number of elements. Also, prepending a string like that is not O(n). Inserting to the front of a string (assuming the string is contiguous in memory) is exponential curve. The code would become unusable with just a few elements because you need to allocate/move the entire array to make space for the element being inserted to the front.
Its actually a very interesting question. What is the time complexity or string reverse using string prepend? Maybe somebody could elaborate? Its definitely exponential in some form, not sure which exact one though.
By "another n" he meant that the concatenation inside of the loop makes the algorithm O(n^2). It is not exponential, but quadratic. His solution was using a list to allow for constant writing.
Samuel Moss lmao 😂 it will work with any valid 2 sets as mentioned in the interview. Runtime would be linear dependent on the size of the arrays cause we would have to iterate through them to sum up. space complexity should also be linear. And implementation would be super easy. Arithmetic operation on arrays is reliable and easy.
If you wanted to really piss him off during the string reverse, you could have just used a RTL character and said it's O(1). :^) u"\u202E" You're welcome.
@@Gbyrd99 Basically that string becomes a character, and the character tells the text render to do what it does normally in reverse. So basically you can type backwards. I'm not sure if UA-cam sanitizes unicode, but if it does you'll see this backwards: This is a test. Thsi text should be backwards.
It was kinda hard to hear what they were saying so sorry if my question is dumb, but in 10:10, why not just do: def find_missing(full_set, partial_set): missing_items = (set(full_set) - set(partial_set)) return missing_items Why did he type all the extra stuff if you're just trying to find the missing item/items of the list? Again, this could be a dumb question. Were they just looking for different ways to get the job done?
the missing item in array he specified ONLY ONE missing item and they are ALL integers. wouldnt easiest method be to sum both arrays, then find the absval of the difference between the two sums?
1st: def rev(x): return x[::-1] print(rev("Apple") 2: def find_missing(arr1, arr2): result =0 for i in arr1+arr2: result ^= i return result print (find_missing([4,2,5,5,6],[2,6,5,4]))
I think he's doing a good job, but in these types of interviews, you need to kind of show a little stress and perhaps a show of speed, while also being personable. It's kind of like... uhm... uh... ect. You don't want to sound arrogant or cocky, but you do want to sound sure.
I don't know if I would agree. Not being sure and admitting to it, but showing your thought process and how you come up with a solution to something you haven't done before shows how you would deal with new challenges as well. And that could also be a good thing. Wouldn't it?
lol this is so funny. um hmmmm ummmmm hmmmm so this goes like this, now we increment i,hmmmm ummm, there we go, the optimal solution for dijkstra's algorithm.(thinking in mind: god damn it, that was so hard, it was hard because I had to fake that I never saw this problem before, but I remember it word to word, variable to variable **cough**cough) and then that person ended up getting $400k offer from Google.
This has got to be the easiest interview ever. Here I am learning about increasing the runtime of recursive algorithms with memoization. I assumed these interviews were meant to break your will to live; this just increased my confidence tenfold.
That's still O(n) since you need to run through each element once. Also, like he said, there's the risk of overflow and underflow in the sum, as the sum also scales with the input.
Solution at 11:29 is logically incorrect if we have duplicates in first array and that duplicate is missing from second array and since he set() those array, the output would be empty set
I wish they would've asked me this on my interviews. def missing(a, b): if len(a) > len(b): return sum(a) - sum(b) elif len(a) == len(b): print(“there is nothing missing”) else: return sum(b) - sum(a)
I think convert list to set in the find_missing problem is not a good choice since if the missing one is just one of the duplicate pairs, and you just drop it away
Idk if the interviewer was aware that his constructive criticism on naming was a mute point in python. Str is a reserved word. I would just comment what the variable is above the function or in a docstring like you would in any production code.
TheRealFarm *moot(not being demeaning, just thought it’d be nice to know) Regarding the interview - he might’ve advised it so that the interviewee can utilise what the interviewer said for other languages should they get the job
While I agree that calling a variable str is a horrible idea, it's perfectly valid. str is *not* a reserved word. It's a function just like all others and can be overwritten if you wanted to do so. There are a handful of keywords in python that are reserved (like del, assert, return, yield, print (in py2)) but everything that is a function can be overwritten.
Want to give it a shot?? Sign up with us to make sure your upcoming interviews are the best they can be by practicing with our experienced engineers. interviewing.io/signup?.com&
"Go ahead an pick whatever language you like to work in"
"Ok i pick English, this should be easy"
You mean SQL.
i laughed way to hard for this
Uh he means Python...
you made my day
Oh lol i like this
Inerviewer: Choose any language you want.
Me: Ok, python.
Inerviewer: Ok great. Lets Go.
Middle of first problem....
Interviewer: Forgot to mention, you cant use any of pythons features.
Me: Can I change to C?
:D
Do u mean built in function ?
😂😂😂
Got the awkward goodbyes down perfectly!
lol
Interviewer: Do you have any questions, I'll be happy to answer
Me: Wtf is your x problem?
Lmaoooo. My ribs
just hearing this intro gave me anxiety
glad he got accepted on the job
I mean reversing a string isn't difficult at all
@@chappie3642 sounds like youve never had a technical interview
Chappie yeah
I dont want to learn to code anymore
he should've chosen 6502 assembly as his programming language of choice.
spearPYN learning 8051 assembly rn, wanna die
@@coolkatmehrfth Im pretty sure people who worked with that... pretty much had no life to begin with... you cant die when you don't even have a life in the first place :)))
Or brainf*ck
Protip: if you know you're not going to get the job, just say I love you before you guys hang up.
yeah, i dare you
Yeah way to get yourself blacklisted from other acquaintances of that guy in other companies.
What if it was between different gender lol
It was a mock interview btw
@@tommyphilip2000 Only a butt hurt moron would blacklist you. Anyone else would just shrug it off.
My favorite about the entire interview is the fact that the interviewer is called “The Legendary Artichoke.”
I really dont think these types of technical challenges find good developers, I think they just find developers who either know the syntax of a language in depth or happen to have done the exact problem before.
Taking the problem at 9:05 as an example, I dont know how to do this in Javascript syntax (I work in Javascript every day). However I know what I need to do, and googling it gave me a 2 line answer in less than 10 seconds.
So I would have failed this test, but would have completed it in under 10 seconds in a real work environment. I dont think this makes me a bad developer.
I think much better technical interviews are to present the user with an already working bit of code (or not) and get them to expand on it, or fix it, using what is already there.
Yep, there is no need to reinvent the wheel. It's inefficient and a waste of time.
Practical tests, doing what the job requires on a daily basis, are the only reasonable way to test candidates. I agree completely.
Was looking for this comment.
+ The fact that they are talking about complexity and time but IRL it depends on how the language is interpreted by the machine. If you're not working on complex algorithms, you never do this.
Agreed. The skill that the interviewer testing here is not just dev skills, but also computer science principles, which based on which company hires you, treats as important to churning out code. For IT services based company, which are focused on realizing business use cases, time and space complexity might not matter as much as code maintainability, code refactoring etc. But it would matter for product companies like Google, Amazon, where every microsecond and byte saved makes a world of difference.
exactly. That is my exact perspective. You are just catching a developer who failed that question before, so they remember how to solve that particular problem the next time it gets asked.
This was probably my favorite interviewer from the ones I've seen. Clearly experienced, not bothering to write long problems on screen, or setting the parameters of the interview and just letting it flow, be more human. You don't need to go all Voight Kampff on someone to get a good sense of their skills.
Point well made
Yeah exactly dude, it's more of a test to understand if the guy who's writing the reverse a string answer didn't just memorize the thing in X language and wrote it up and not knows what he is doing, much better to ask explanations of simple problems and why the answer you think is the right one is the right one. Good engineers are not ones that mug up but ones who actually can create shit from pre existing shit and somehow better it up !
Santiago Méndez do you code iOS apps?
Lucifer Morningstar do you code iOS apps?
Oh yea?!? Then how are you supposed to know if they are a Replicant?! Due diligence dude. Due diligence.
This guy clearly has more of an object oriented background. Interviewer was a data systems guy
If you've ever hired a developer that didn't know how to problem solve and use very simple language constructs you know the value of these tests. Maybe they are a little academic but most times they are trying to understand your problem solving ability not your knowledge of obscure language concepts.
We hired a guy that had an amazing CV that looked like he could've invented Java himself when we got him into our department he was a nightmare and had almost no concept of how to problem solve in code. It was a disaster and the company that hired him was a charity that felt too bad to fire him otherwise he would've lost his visa.
I have an issue with this type of interview. High performance "reverse" algorithms are pretty much only useful for working with really massive datasets, like DNA/RNA. The real issues that businesses face have to do with solving business problems. Reversing a string is not a business problem. Anyone can look up the "current, most optimal way" to solve your sorting problem, reverse problem, etc. It takes an engineering mindset to architect a solution to a business problem, though... which is a totally different skillset and what pretty much every company actually desires (outside of research and game engine development). I have had many interviews and given many interviews where wrapping your head around a real life problem gives far more information about the ability to engineer software.
"Say you have 50 requests coming in every second to your online shopping product catalog. How do you best serve that data to your customers if that data is sitting in your database?"
Answer:
1. "Pull the active product data into a cache, where the data is easy to sort and categorize for the filters the customer selects. This way, the customers are searching in-memory data."
2. "Load balance customer requests over several web servers so wait times are shorter. Ensure your web servers have available resources (bandwidth, RAM, etc) and your database server(s) has a reasonable number of connections available and that each query returns the smallest dataset."
3. "Optimize filtering to reduce the product set as quickly as possible. Smaller datasets are far more performant. This might limit the number of products a customer sees at once (say, the first 20 results)."
"Assume your customers have to upload numerous high quality (i.e. large) images to your site. How would you handle this?"
Answer:
1. "Bandwidth will be an issue. Many areas do not have gigabit fiber. Colocation can have anywhere from 20-100 mbps on a standard connection. If you have 12 Megapixel images, each one is roughly 12 Megabytes (or more, if they have higher color bit rates). 12 MB * 8 bits/byte = 98 Mbits. So a single image can max out the available download pipeline of a small operation, if only for 1 second. In reality, customer upload speeds will vary wildly. The images will need RAID storage, for performance and safety (backup)."
2. "If cost is not too big of an issue, consider cloud storage. This will alleviate issues with load balancing, bandwidth, storage space, and image backups. It will also provide high availability and allow your business to expand to other global regions, quickly. This may take the form of a Kubernetes cluster."
I don't expect a candidate to know "everything". I expect them to give it their best shot. Then I might have them draw a diagram. Or write out a SQL query. Or pseudo-code a small piece of their response.
Do they focus on hardware solutions? Do they focus on database solutions? Do they focus on software solutions? Do they understand current tech trends?
Are they a capable problem solver? Do they think through the solution? Do they get frustrated? Do they ask for help? Do they throw out ideas? Do they eliminate bad ideas? Do they ultimately solve the problem? Do they make excuses? Do they enjoy the process? Do they get completely stuck? Did they lie about their skillset on their resume? Would you enjoy having this person on your team? Would they bring new approaches/skills to the table?
To me, memorizing algorithms just tells me that they studied like it was a college test. I have worked with DNA, so I know that performance is important, but it isn't great for a job interview question. It's also one Google search away. Looking at a real problem requires multiple approaches and an accumulation of knowledge (the thing you need humans for). I've had the pleasure of working with, and learning from, very talented people. It's difficult, in my mind, to find those people with this type of approach.
Finally someone said it
its difficult to find those people because they are leading a business. If you are capable of thinking like this you won't bother working for someone else.
@@QuiiKSyyntax I don't agree. Having business skills is completely different. Knowing when to get a lawyer involved, contract negotiations, taxes & expense management, hiring, sales, finding new clients... these are all way outside most technical people's wheelhouse. I think most technical people don't want to deal with the business, so they work with companies that allow them to do what they do best. I've met a lot of really talented developers, none of whom run a company. Are they smart enough to run a company? Probably.
Matthew those business skills won’t get you anywhere when trying to build your own business without beeing an expert at something. There are two options tho, either you make your business knowledge a business itself or you have the money to hire the people you need to do stuff you can’t. While people with problem solver attitude and beeing an expert at something can all be great business leaders, because not figuring something out is not an option.
Matthew hey Matt do you code iOS app?
dude just casually pulling out the xor. didn't know it could be used like that, pretty neat
ageofwar2000 negative indexing is bad form
Yea I put that in my notes now!
Question: first time i've seen xor here other than in minecraft gates from 5 years ago. Is this the biggest application? Finding the missing number?
@@redwoodenjoyer Biggest application is in cryptography IMO. It's very fast to compute, easy to understand, commutative and associative !
Basic example of a XOR cypher : en.wikipedia.org/wiki/XOR_cipher
blake XORs largest application is actually probably for a full-adder implemented in hardware honestly. Total # of XORs used for that purpose has to be in billions/trillions at this point
literally 27 min of my deepest anxiety
the math knowledge for this is sure gonna come in handy when he starts working in a few weeks gluing apis and learning the aws sdk 🤔😆😆😆
@@BootlegKoolaid no
haha isn't that the sad truth
Yeah pretty dumb stuff these interviews... always the same textbook question with no real application. These engineers are stuck is the 80s and don't want to grow out of it.
@Winston Mcgee There is no math in gluing API's either... That is his point.
lmfao!!!
For the one-liner programmers this would be solution for the technical questions
# Reverse string function
def reverse_string(input_str):
return "".join(str[::-1])
# Find missing element in the list
def find_missing_element(list_a, list_b):
return [x for x in list_a if x not in list_b]
regarding to the variables names in the find_missing_element function, I think it need to be clear which one is the full list and which is the partial list.
A side note, the interviewer said that he would use "str" as a variable name for the reverse function but actually I am not fan of using just "str" because it's a python built-in function and it might cause a syntax error.
"Such as heap sort which you may vaguely remember?" *long pause* "yep." as he exhales xD
all the while he was thinking "please don't make me implement heap sort please don't make me implement heap sort." just one of those things where you know you can probably do it if you had to, but you just never want to.
This is the Legendary Artichoke interviewing Mammoth Avenger, live on CTV news, back to you kelly !
This dude has some talent! He works through the problem with the interviewer and tells him what's going on in his head. I bet this dude got hired.
I'm wondering if he got a call back. Young kids are so so cute when they're nervous. I'd feel bad if he didn't get it.
Probably not since it's a mock interview
This is the only negative to development jobs. The ones that require this sort of pressured interview.
James Liscombe are this kind of coding interviews common?
Eduardo Fernández Díaz yes
@@eduardofernandezdiaz5264 This is like the only way you're interviewed.
I have one coming up soon 😢
Breathe the pressure, come play my game I’ll test ya.
This guy solving the first problem.
Interviewer: "Stop it. It's dead already!"
When in doubt, always use a HashMap or Set (or a Dictionary to my C# people)
Interviewer: "Such as heap sort, which you may vaguely remember"
Interviewee: "......yep"
I can't believe it take almost the entire interview to come across an alternate algorithm of sum(full) - sum(partial) = missing element
Yes, so it's basically can be done in O(n) time and O(1) space! I was also thinking about why didn't find the solution. Because when the interviewer said "only one element missing" then my first thought was missing element = sum(full)-sum(partial)
I've been programming for 5 years and knew the answer instantly, but not with the XOR... Wtf. My whole life is a lie.
For the second problem: Simple swift solution which just sums up each array and returns the difference which is the missing element. O(N) time O(1) space
func findMissing(_ fullArray: [Int], _ partialArray: [Int]) -> Int {
let sumOfFull = fullArray.reduce(0, +)
let sumOfPartial = partialArray.reduce(0, +)
return sumOfFull - sumOfPartial
}
If there are multiple items missing.. we just make a set from the partial array and iterate through the full array and keep track of what items aren't contained in the set: O(N) Time & Space
var set: Set = []
var missingNums: [Int] = []
for num in partialArray {
set.insert(num)
}
for num in fullArray {
if set.contains(num) == false {
missingNums.append(num)
}
}
return missingNums
I don't know. Never worked in a company that cares about time complexity. Unless you are doing low level, high-speed services, it really doesn't matter. What matters more is readability and maintainability.
Really? I think these interviews are exaggerated but time and space complexity knowledge was important even for me who only did internships and haven't graduated yet.
@@windskm In the general industry, it doesn't matter. Everything is based on how quickly you can get a product to market. Firms are more than happy for you to use a couple more E2 instances to handle the load and get the feature 50% faster to the users because you used a pre-defined logic.
Another good example is immutable functional programming, every "map, flatmap, filter etc" will create a new collection or monad. It's wasteful cpu-timewise (and memory wise). But it's more deterministic, easier to read and faster to get to the market.
Even in data science, rarely who would want you to manually rewrite neural nets from scratch if you can simply wire them with pre-written modules by Google.
Now, there are exceptions (as I mentioned). The core teams. They must care about deep level dynamics. If your team develops the core frameworks that will be used by other teams, every small delay in your core will impact their end products.
@@artursvancans9702 ahhh gotcha. Yes, I think that makes senses when developers don't need to care about server bills. Still, if there's a clear O(n) solution to a problem than why do an O(n**2)? I think that's why companies who run a lot of their infrastructure (google, mcsft, facebook) want every single one of their SWE engineers to know this, even if they are front-end, back-end, dev-ops, low-level or whatever.
@@artursvancans9702 I agree about "memory wise". Cpu-timewise - it depends what your map/filter/grep is doing.
@@ItsMeChillTyme It always depends on the job culture. I have seen some contractors trying to keep everything as secretive as possible. Mostly happens in corporate environments. However, usually you work in a team, your features are PR'ed or worked in pairs. The convoluted code will just simply not get to the prod. Even if you work solo, in most cases your tech lead or head of tech will follow Bus Factor, that will make sure at least 2 other people can replace you at any point.
TLDR - It happens. But in shitty companies.
To all the people who are commenting that these are real world problems or they wont be used in development, i am sorry to inform you that this interview isn't intended to check your programming skill to glue API or other stuff. The main aim of these type of interviews is to check the approach a person uses to get to the solution, if he/she gets stuck at some point, then what is their attitude towards that difficulty. Real world problems dont get solved during the one hour or half hour interview. They require people who built solutions to a problem, there is nothing special about people who glue API together. API is based on work did by engineers who are capable to solve such problems.
For most jobs worth wanting, more important than big O is *being cool*. Being friendly, easy to chat with, and interested in the person you’re talking to.
This comment deserves a higher rating
when everyone is saying these questions are easy but you don't know whats going on...
It's kind of fundamental stuff as far as programming goes. You can program without knowing this, but unless you have a basic understanding of time & space complexity, you can accidentally write code that is suuuper slow.
@@joshodom9046 I'm confused about time complexity. What is the time complexity of string reverse using prepend approach? I'm thinking its N log2 N
@@kristupasantanavicius9093 in a language like python, strings are immutable, so you create a new string through copying. Copying a string with m characters will take m operations. If you perform the copy operation in a loop, from 1 to n, you get 1 + 2 + 3 + ... + n-1 + n. You might know that this can also be expressed as n*(n+1) / 2. Expanded, this becomes n^2 / 2 + n / 2. We aren't interested in coefficients, and only the most significant term, so this all becomes O(n^2).
In practice, copying a string with m characters might only take m/8 instructions (copying a word at a time, instead of a byte at a time). However, if you plug this into the above, you will still get O(n^2), because the coefficients are discarded. Note that either way, this copy operation is O(n).
Time complexity is compositable; if you are combining 2 algorithms, or using an algorithm in a loop, you can use the time complexities of the individual algorithms to find the overall time complexity.
Hope this all makes sense
@@joshodom9046 Nope, it does not... Where can self taught programmer learn such a things.
@@mardvorak2 well, I learned the concept in my data structures and algorithms class in college. I bet you could find a free course online that covers this. Otherwise, I dunno, the internet has everything nowadays
Please continue doing this.... So helpful 👍
Great interview, some commentators are obviously extremely infatuated with themselves and do not understand what stress is until they are at an interview themselves, but this guy did awesome. Really cool I greatly enjoyed this and shows I have some common thinking.
It is a mock interview on the other hand.
@@VirtuelleWeltenMitKhan it is? I sounded like a real one. That guy was nervous as heck i would be too. But hope i will be more confident
@@ninjaninja9954 It is in the description of the video:
"This is a recording of a mock interview in Python by a senior Airbnb engineer"
@@VirtuelleWeltenMitKhan ic. Yeah he is just nervous in general. All these questions arejust algo stuff
first question answer in typescript :
function reverseString(str: string) {
const splitedString = str.split(' ');
const stringLength = splitedString.length - 1;
let arr: string[ ] = [ ];
for (let index = stringLength; index >= 0; index--) {
arr.push(splitedString[index])
}
return arr.join(' ');
}
One cool recursive way of doing the first one that I learned is this:
def reverse(s):
# Base Case
if len(s)
I don't think the complexities are correct
Pretty smooth interview.
I got asked "How to serialize a tree structure" in my last interview 🤷♂️
Nobody Cares Serialisation and deserialization is essentially taking a tree data structure and removing the values in a certain order (tree shifting each time) and putting it into a new tree. The only difference compared to a linear data structure is the order of removal and order of placement instead of FIFO
@@LandCruisin well you can ask the interviewer and he/she will now be flustered to answer the question. You have essentially turned the tables lmao
I am not a CS guy. But you can serialize any sort of trees into essentially an XML or JSON like file right or am i wrong on this ?
@@pointinpolyhedron yes that's kind of correct it's just you have to keep track of where all the null values are and how many branches there are for each node before you insert into JSON. That's the tricky part
4:31 when you start blaming the language lmao
10:47 interviewer did that too lmfao
By the way, mind you this is just 1st round. It's not like he is going to get an offer by reversing a string.
Then you have to do multiple technical rounds consisting of design and architecture related questions.
Nowadays they test EVERYTHING.
From developer common sense to architecture of the system.
After 5-6 rounds of this you get a result which is again very low for such companies.
Interviewer: Pick whatever language you want.
Interviewee: Ok then I pick *assembler*
😱😂
Hahah. Imagine picking something really esoteric looking, like J or something
PowerPC machine code written raw in a hex editor ;)
Interviewer would actually use str as variable name? Yikes
str = "hello"
one = str(1)
.....
He is probably more familiar with other programming languages other than Python, although he knows the strings are immutable in Python :)
there is special place in hell for people who, in python, name their variables with a data type: int, str, dict ...
The questions are really simple:
#Question 1
def reverse(s):
return s[::-1]
s = "abc"
print(reverse(s))
#"cba"
#Question 2
def findLast(l1,l2):
for i in l1:
if i not in l2:
return i
l1 = [4,12,9,5,6]
l2 = [4,9,12,6]
print(findLast(l1,l2)) #5
Why isn’t your second answer’s logic more popular?
I had one of these "blackboard" interviews with Indeed. Honestly, it did not prove that I was a good Python developer or not. I was more nervous than anything while doing it.
Listening to this muted, sounds good
1. return x[::-1]
2. Just do binary xor for all numbers in both arrays, the result will be equal to the missing number. O(n) time, O(1) space. Like:
return functools.reduce(itertools.chain(arr1, arr2), operator.xor)
no built ins
If only one number is missing then I like:
def find_missing(x, y):
return sum(x) - sum(y)
9:20 if the arrays are numeric I would just add up the values to get the missing one by subtraction.
But that is very limited.
edit: Ah ok, it is mentioned at 19:30
bruh that's like 2nd grade problem. just to Return list(x for x in full_set if x not in partial_set).That would also work if there are more than 1 element missing.
@@Sennken I always envy the US for teaching programming in 2nd grade.
def StringReverse(astring):
astring = str(astring)
reversed_string = astring[::-1]
return reversed_string
This is a much easier way of writing a function which reverses strings
int missing_item(vector v1 , vector v2){
int sum1 = 0;
int sum2 = 0 ;
for(auto x :v1)sum1+=x;
for(auto x : v2)sum2+=x;
return max(sum1,sum2) - min(sum1,sum2);
}
So interesting that people often assume atting charscto a string is O(1) operation. This must have been his thought Wenn claiming it is linear in time. I really loved the xor approach (:
Damn dude I see you everywhere (Bitcoin twitter)
As far as I remember Joel Spolsky even has an article about people not knowing how basics work
Do Airbnb engineers use 5$ walmart microphones? Goodness the first impressions...
Python scripters are very poor. The rates are extremely low. Due to low learning curve and low intelligence required to learn it. But this guy still don’t know basic stuff.
@@johnmadsen37 My brain hurts reading this.
@@johnmadsen37 nice troll
@@gilfhunter42069 hehe yes. actually, data scientists use py -- high mathematics and stats or genetics - very high skillset, very high pay. but that is probably 5% of all the jobs. the rest is like every other language - an average (of programmers) person can do it. So especially for this vid, my statement is most likely right on the money.
@@johnmadsen37 Well, I don't know. As long as you need a degree for the job, the pay of a python software engineer (which is usually connected to machine learning, data science or simillar fields, because why else would you want to use python in enterprise situations) is high
Neither of you were right about which sorting algorithm Python uses. It's not a modified quicksort, but a modified mergesort that uses insertion sort once the sublists get small enough for improved cache behavior called "Timsort"
en.wikipedia.org/wiki/Timsort
lol when you ask the interviewer if you can google the answer xD
Idk how effective these tests are. I mean yes, it is good to know the syntax of a certain language as in-depth as you can. And you should be able to think about a problem given to you and think of multiple ways to get to the solution.
But then again, going to stack overflow can get you your solution in a matter of seconds. What matters most on the job is your resourcefulness and persistence.
You can't really determine that about a person just from one interview.
the interviewer said that he would name the string str at 26:06 but that no one would actually do that since str() is a built in function in python lol
You can name function arguments str in python without any issues, as long as you don't need to use native str() in the function
@@justarandomcitizen210 i was wrong, it actually does compile but it's just not good practice. sometimes it works but nobody who codes in python would do that since it's a native function and this can lead to many errors/unintended consequences. this is okay in java, C, and many other languages but not python. just a nit picky detail
The interviewer doesn't have to know the language, how do you expect him to know each and every language?
What he's testing is your problem solving
@@chappie3642 I mean I would except him to at least know what you should and shouldn't name stuff in Python if he's gonna suggest something like that
@@chappie3642 The correct way to solve all the questions is to go to stackexchange and copy and paste the answer because it's already there for you.
For improving time complexity at 4:46 he could run x[::-1]
def find_missing(lst1, lst2):
for x in lst2:
if x in lst1:
lst1.remove(x)
return(lst1[0])
This is the simplest solution without sets
Why not [::-1] for reverse?
Can you explain the space and time complexity of the internal Python implementation of that syntax?
@@sliderBro No new allocation, it's (O)n, because it's only using the step argument of string slicing. It's the equivalent of starting at &string + sizeof(string) and decrementing the pointer by 1 until 0 in C. Pro Tip: A strong understanding of C really helps out in python, as the types in python are usually more complex object types from C (list, dict, etc).
Hell, dude could've just "for i in range(len(string), -1 -1)" and it would've been better.
@@mattymattffs dude. That immediately went through my head
What the hell was the point of that?
And im not quite sure but appending it to the end of the list would make that O(n) so better than his concatenation
raskec1 exactly
Technical interview: loosely translated, an hour of ignoring the fact modern languages handle these operations for us so we can make ourselves feel clever.
Interviewer: You need to implement a function to reverse a string, how would you do it?
Bad answer: Explain how to write a program to reverse a string.
Good answer: Use the built-in string libraries reverse function every language has.
Interviewer: You need to divide numbers but your dog ate your / key, what do you do?
Bad answer: Explain how to divide using bitwise operations and subtraction.
Good answer: Get a new keyboard.
Interviewer: They can't afford a new keyboard.
Good answer: Quit and get a new job, this place is going bankrupt.
xor solution caught me off guard, so genius, no way I'd ever come up with something like that myself
The functions are very easy but then the interviewer throws in questions like what are the time and space complexities of sorting algorithms. That's going to catch anyone off-guard, especially junior developers.
The solution for the second problem can be obtained better than O(N) : Difference between sum(original set) - sum(input set). This would work as the interviewer made it clear only one element would be missing (regardless of if elements were positive/negative integers)
sum(original_set) - sum(input_set) is still O(N) (plus he actually talked about this exact solution in the interview)
I think we can just XOR all elements in two Array. cus if A^x = B, then A^A^x = A^B, then we got the missing element is x = A^B.
not your fault or anything but these interviews are so painful to watch, I hate these sorts of situations
well im gunna go brush up on time complexity
Really not hard unless you wanna be specific like setx - sety is actually O(len(setx)) avg case in Py but this guy wasnt expected to know that either. Anything that does one thing is O(1), a loop is O(n), except for loops where you can break or otherwise not process all elements those are log n. And nested loops are multiplied [2 nested for loops would be O(n.n) aka O(n²), non nested loops would be O(n+n)]. Also good to do in interview if you're confident is ask if they want to know avg or worst case
Ah rite, well luckily I don't have an interview for a long time so I'll hopefully be ready by then hehe
0x1 thx man that didn’t sound quite right
Not as painful as reading through job postings.
Couldn't hear very well, but I tried following along with the results:
def reverse(x):
return x[-1::-1]
i = reverse('Hello!')
print(i)
"""
"""
# 08:14
def findMissing(x, y):
for i in x:
if i not in y:
return i
x = [4, 12, 9, 5, 6]
y = [4, 12, 9, 6]
z = findMissing(x, y)
print(z)
"""
Can't you reverse a string in python by creating a slice that starts at the ending position and moves backwards?
def reverse(x):
return x[::-1]
I think there is no faster way to reverse a string in python but this is still O(n) time complexity.
Not really what the interviewer wants to see most likely
Where the hell is the code output?
And yet you never use this in real working environment. (When nerds become the bosses)
Those are the worst interviews. I would rather want to see reverse python built-in function rather than that overly convoluted for-loop solution. A better tech interview would be them talking about higher-level and architectural problems.
You are both missing the point. He is testing his problem solving skills and his thought process, that's why on many interviews I hear "please think out loud". Whether the problem he solves is useful doesn't matter at all.
NDD He’s asking for specific computer science problems to solve. This problems have hardly any application in real life. You could be dismissing real problem solvers for folks that read a Wikipedia article before the interview.
Three solutions in 10 minutes for find_missing
#use set Time O(n), Space O(n)
def find_missing1(arr1, arr2):
sa = set(arr2)
for a in arr1:
if a not in sa:
return a
return None
print(find_missing1([1,2,3,4,5],[5,4,3,1]))
#use math sum, Time O(n), Space O(1)
def find_missing2(arr1, arr2):
return sum(arr1) - sum(arr2)
print(find_missing2([1,2,3,4,5],[5,4,3,1]))
#use bit operation, Time O(n), Space O(1)
def find_missing3(arr1, arr2):
ans = 0
for a in arr1:
ans ^= a
for a in arr2:
ans ^= a
return ans
print(find_missing3([1,2,3,4,5],[5,4,3,1]))
second question :
let tab = [4, 12, 9, 5, 6]
let tab2 = [4, 9, 12, 6]
let res = []
tab.forEach(val =>!tab2.includes(val) && res.push(val))
console.log(res);
Kinda tired right now, but I think he could find the missing item in just O(n) with something like this:
function findMissing(fullArray, partialArray) {
let index = 0, fullArraySum = 0, partialArraySum = 0;
// Using while instead of for because we don't want to do an extra iteration
// for finding the fullArray length.
while (fullArray[index] !== undefined) {
fullArraySum += fullArray[index];
partialArraySum += partialArray[index] ?? 0;
index++;
}
return fullArraySum - partialArraySum;
}
findMissing([4, 12, 9, 5, 6], [4, 9, 12, 6]);
// 5
Why did they never actually run any of the code? Like they never called any of the functions... I didn't watch the whole thing to see if there were any clear mistakes, but they kept saying 'it works' when they really only checked if the interpreter would syntactically accept that code...
They're checking for process, logic and problem-solving, not linting for small errors in the code... would be my guess anyways
Matt Billenstein What did you think was happening everytime he said “let’s give it a quick run” followed by long silence, followed by him saying “it works”? Here’s the last one of about five or so times it happened: 23:10
He was running the code on his end, probably even copied it directly out of the interview interface and onto a separate environment just so he could see the results and say whatever he wanted to the interviewee (maybe even lie or mislead them in the results to see if they stick by and defend their code or roll over and assume it’s wrong even when it isn’t)
I really do hope that most prospective technical employees know that just because you don’t see something on screen doesn’t mean that it isn’t happening on the other end. Otherwise all our future backend developers will start to leave for GUI and front end development not realizing there’s more that makes their programs work than what they actually see. 23:10
Dave Hyler just checking syntax - what do you think is happening?
@@HylerMusic I've done a bunch of these - never seen someone run it off-screen when you can just run it in the tool there.
Matt Billenstein what do I think is happening? Exactly what I stated is happening, the code IS indeed being run and it confirms it on screen every time it runs on the timestamp of “extenuated at”. Look at the time value changing above the part that says “Mammoth Avenger ran 29 lines of Python.” And notice how every time he runs it the time stamp changes it to confirm he ran it again at the most recent time?
So “what do I think happened”? I think Mammoth Avenger’s code was RUN several times by him and/or the interviewer, because it literally says it was and even confirms it every time above “ran code” changes (and I recall it changing at least five times)
first solution is not O(n), its O(n^2)
Python does not use Quicksort lol. It uses Timsort which is a hybrid sort using both merge sort and insertion sort
@@kieranhorganmallow Can you show me any link or documentation that says it is quicksort not mergesort?
Any article could be wrong so lets go straight to the source.
github.com/python/cpython/blob/master/Objects/listobject.c#L1881
This is the code that performs the merge operation on a list sort.
github.com/python/cpython/blob/master/Objects/listsort.txt
You can also take a look at this link which describes and compares the performance of the sort
@@kieranhorganmallow Also, I just noticed you said quicksort is faster on average than merge sort, quicksort has the same speed as mergesort both on average and in the best case. The advantage of QS over MS is that QS uses O(log(n)) space complexity where MS needs O(n)
find missing function can use bit-wise NAND to arrive at O(1) solution. both interviewer and interviewee are mistaken
for the problem where we find the missing item in an array, here's the logic i could come up with using javascript. i loop through the second array (using a typical for loop of course), so i check if an item from the second array is present in the first array. If it is, i'll delete it from the first array. I repeat this process until only the missing items are left in the first array. Then i just return it is as "THE MISSING ITEMS!!!".
Does anyone know if he has a vid with using C++?
Can somebody explain to me the time complexity of string reverse? What do they mean Big O on N? O(n)? Then the interviewee says "its another N"??
You can't have 2N, because time complexity is not measuring the time taken, but rather the time taken relative to the number of elements.
Also, prepending a string like that is not O(n). Inserting to the front of a string (assuming the string is contiguous in memory) is exponential curve. The code would become unusable with just a few elements because you need to allocate/move the entire array to make space for the element being inserted to the front.
Its actually a very interesting question. What is the time complexity or string reverse using string prepend? Maybe somebody could elaborate? Its definitely exponential in some form, not sure which exact one though.
By "another n" he meant that the concatenation inside of the loop makes the algorithm O(n^2). It is not exponential, but quadratic. His solution was using a list to allow for constant writing.
@@kristupasantanavicius9093 not exponential. it is quadratic / parabolic
In the second question of finding the missing number, is there any reason for not using the solution as "return sum(a)-sum(b)"?
in my opinion that’s totally fine and it was the first solution I thought about.
For the particular input, it would work. but it would easily break for anything else like
set1 = [1,2]
set2 = [1,2,3,4]
this would return 7
amzshow4life that’s got 2 elements missing lol
Samuel Moss lmao 😂 it will work with any valid 2 sets as mentioned in the interview. Runtime would be linear dependent on the size of the arrays cause we would have to iterate through them to sum up. space complexity should also be linear. And implementation would be super easy. Arithmetic operation on arrays is reliable and easy.
integer type overflow, I guess
the interviewer sounds like DJ Vlad
8:16 "Ok that looks good" NO IT DOESNT
yeah it could be done in one line
If you wanted to really piss him off during the string reverse, you could have just used a RTL character and said it's O(1). :^)
u"\u202E"
You're welcome.
No you're just deferring the operation to some OS specific stuff which you probs dono the time complexity of
@@doldol1 The time complexity is O(1), tard boy.
It's just RTL instead of the default LTR. The text renderer works the same way.
What you mean. This sounds intriguing
@@Gbyrd99 Basically that string becomes a character, and the character tells the text render to do what it does normally in reverse. So basically you can type backwards. I'm not sure if UA-cam sanitizes unicode, but if it does you'll see this backwards:
This is a test. Thsi text should be backwards.
I hate these types of interviews. This is why I will never leave my current job.
Is there a reason we can't see the output when he runs it? Was this a "passing grade" interview, meaning did he make it and could it have been better?
It was kinda hard to hear what they were saying so sorry if my question is dumb, but in 10:10, why not just do:
def find_missing(full_set, partial_set):
missing_items = (set(full_set) - set(partial_set))
return missing_items
Why did he type all the extra stuff if you're just trying to find the missing item/items of the list? Again, this could be a dumb question. Were they just looking for different ways to get the job done?
So basically you have to have done a first year introduction to programming course.
the missing item in array he specified ONLY ONE missing item and they are ALL integers. wouldnt easiest method be to sum both arrays, then find the absval of the difference between the two sums?
1st:
def rev(x):
return x[::-1]
print(rev("Apple")
2:
def find_missing(arr1, arr2):
result =0
for i in arr1+arr2:
result ^= i
return result
print (find_missing([4,2,5,5,6],[2,6,5,4]))
x[::-1] is python syntax sugar and is equivalent to reverse(x). The interviewer explicitly asked for own implementation.
@@artursvancans9702 oh okay
I think he's doing a good job, but in these types of interviews, you need to kind of show a little stress and perhaps a show of speed, while also being personable. It's kind of like... uhm... uh... ect. You don't want to sound arrogant or cocky, but you do want to sound sure.
Stephan Salas do you code iOS apps?
I don't know if I would agree. Not being sure and admitting to it, but showing your thought process and how you come up with a solution to something you haven't done before shows how you would deal with new challenges as well. And that could also be a good thing. Wouldn't it?
lol this is so funny. um hmmmm ummmmm hmmmm so this goes like this, now we increment i,hmmmm ummm, there we go, the optimal solution for dijkstra's algorithm.(thinking in mind: god damn it, that was so hard, it was hard because I had to fake that I never saw this problem before, but I remember it word to word, variable to variable **cough**cough)
and then that person ended up getting $400k offer from Google.
For the second, what if i sum up all the number and then minus the other's sum
Better yet, to avoid potential overflows (if not Python), XOR all the numbers and you get the missing one.
These are really awesome, please keep making them! :)
Just xor the two arrays, result is the missing item. A^A=0 and A^0=A
This has got to be the easiest interview ever. Here I am learning about increasing the runtime of recursive algorithms with memoization. I assumed these interviews were meant to break your will to live; this just increased my confidence tenfold.
Jan Hoekstra it’s not, and a lot of jobs have training anyways
16:50 fun fact, python uses an insane mostly-in-place merge/insertion sort hybrid as its sorting algorithm -- timsort! en.wikipedia.org/wiki/Timsort
why cant I just sum first and second and subtract them if they are unique numeric ids?
Exactly what i did. Wouldn't work if multiple items are missing though
That's still O(n) since you need to run through each element once. Also, like he said, there's the risk of overflow and underflow in the sum, as the sum also scales with the input.
Solution at 11:29 is logically incorrect if we have duplicates in first array and that duplicate is missing from second array and since he set() those array, the output would be empty set
I wish they would've asked me this on my interviews.
def missing(a, b):
if len(a) > len(b):
return sum(a) - sum(b)
elif len(a) == len(b):
print(“there is nothing missing”)
else:
return sum(b) - sum(a)
They did discuss that approach
your answer does not account for integer overflow.
def missing(a,b):
return abs(sum(a)-sum(b))
I think convert list to set in the find_missing problem is not a good choice since if the missing one is just one of the duplicate pairs, and you just drop it away
def reverse(x):
if x=='':
return ''
else:
return x[-1]+reverse(x[:-1])
def reverse(x):
return x[::-1]
what magic is this....it's Beautiful!!!
Have fun throwing exceptions when I throw strings larger than ~1000 at you.
@xOr Python's default recursion limit is 1000.
I am getting anxiety watching this even though I know I am not the one getting interviewed.
Shouldve done String [::-1]
Can't use internal features of the language apparently.
Idk if the interviewer was aware that his constructive criticism on naming was a mute point in python. Str is a reserved word. I would just comment what the variable is above the function or in a docstring like you would in any production code.
TheRealFarm *moot(not being demeaning, just thought it’d be nice to know)
Regarding the interview - he might’ve advised it so that the interviewee can utilise what the interviewer said for other languages should they get the job
While I agree that calling a variable str is a horrible idea, it's perfectly valid. str is *not* a reserved word. It's a function just like all others and can be overwritten if you wanted to do so. There are a handful of keywords in python that are reserved (like del, assert, return, yield, print (in py2)) but everything that is a function can be overwritten.