Welcome to the channel! I make videos about Data Science and Coding Interview Preparation. I am the CEO of MLNOW.ai and owner of AlgoMap.io and its associated coding bootcamp. Email me at greg.hogg1@outlook.com 😊
oh nice I am a beginer and I had a problem similar to search if a num is prime the most efficency plan I had in mind that you want to get n/2 and n/3 and etc until n/(squared n)-1 if it is equal an int and not float its not prime else its prime
There's actually a Formular to calculate the kth element in the nth row when already having the last element. Then you can also use symmetry to reduce it to half.
Man y'all are lucky you get asked these stupid questions in ur interviews. Here in India I have never been asked an LC ez question in an interview. Twice I've been asked LC hards in an hour long interview along with a medium question for an intern position.
Greg… you might want to correct the minheap part… minheap is actually maxheap and maxheap is minheap. I know it’s annoying but that’s just how they named it. Minheap = highest value. Maxheap = lowest value.
Take a variable a = 0. Then start traversing from last and -1 every time when you come to new index check the condition ((arr[index]-a)>=0) if true return true else false run the loop until you reach the start. If any mistake in upper code plz tell me😢
Can’t you just do square root and then compare the square root value with its int casted version? I get that square rooting is quite expensive but I assume the hardware has caught up since the 90s
They want you to find the 2nd higher number in the array heap, you know it's the 2nd higher because k = 2 (if k = 1 then they want the higher). To do so you arrange the array in a way you have the lowest number at the beginning and the higher at the end. Then it's simple you will compare two numbers each time and remove the lowest, when your array of numbers is only the length of k (2) then you remove the higher and return the lowest that will be the only element that's still in the array heap (so [0]) because it mean it was the second higher). Ofc you can find the same return result with one liner code BUT those will re-render the whole array until the result because they will always render the array, take the higher/lowest and kick him, then render the array again and remove again until heap lenght is reach and then give the lowest, with a heap you run through the array one single time because you do actions directly while processing (meaning you remove the higher/lowest while rending the array so the next number of the array come is treated next one come and go one until you have only the length of the array and render the lowest). That was the easy way of inderstanding it, in reality a heap is a kind of array, while processing the array heap[] (the original one) with the integers you push into your heap that's your the trash can, then you are only left with one integer in your array heap (the original one not the kind of array that a heap is) that will be the 2nd lowest because when you reach 2 integers in your array you push into the heap the higher and are left in the array heap with only the 2nd higher.. For god sake, neaming heap the heap was a headache lol In big tech you want to do the calculation fast because it will slow your server and cost you more because of electrical bills (cloud pricing), more re-render of the array = more calculs. Sorry my english is broken as my code lmao
We dont need to run 2 loops. Single loop would be enough with hashmap. Check if target - nums[i] exists in hashmap. If it does then you have indices at i & dict[nums[i]] else add dict[nums[i]] as i