I spent 7 hours without giving a break on "Recover a Tree From Preorder Traversal". But I've solved it at the end. My code was over 100 lines, and I even had to force a hashmap to handle duplicate keys. But it was worth it at the end, and it was my first hard question I've solved. So, one hour on a hard question is nothing in my opinion.
Controversial, but I honestly think a lookup table is a totally valid solution to the first problem and I think having an interview question like that is really valuable. Sometimes there just isn't a clever math trick that makes your program 100x faster. In the real world you need to compromise sometimes and saying "We never expect to receive input greater than n so precomputing f(x) for all x
but there is actually a math trick, and he explains in the video someone solved this problem mathematically as it should be. it is not a bad problem, just people did not want to get involved with math.
Hey Colin, I had a failed attempt to pass an online assessment for Amazon SDE position, and one of the tasks was leetcode # 2281, which is in top 15 with the least acceptance rate. Could you solve and explain it, please?
I wonder if your employer would be more impressed to see you solve a difficult problem in less than said minutes versus communicating which would usually take 3x or 5x longer.
@@vishnuvs6121 You shouldn't be taking pride just in things like leet code, its a fun puzzle game but it shouldn't be a major motivator for you. Programmers are solving problems for people or doing something of value for people over what they could be doing
Hi Colin, For the first problem, the result has to be a palindrome, and apart from n = 1, safe to assume that answer will contain even number of digits. Which means it will be always be divisible by 11. So you can put a condition for one of your numbers to be divisible by 11, only then look for second number possibilities, this will pass leetcodes' time limit. Edit: Just resumed the video and realized this is already covered :)
@@MichaelSt You're multiplying 2 n digit numbers, presumably starting off with 8 or 9 as their first digit. so something like (8 * 10^(n - 1) + something smaller) * (8 * 10^(n - 1) + something smaller). So 64 * 100^(n - 1) + something small. This is clearly even number of digits.
@@saharshluthra6492 a lot of assumptions there, like the number starting with 8 or 9, and the something small not "overflowing" into the next digit. I mean you can convince yourself it doesn't happen for 1
@@MichaelSt The something small is < 10^(n - 1) and it physically cannot contribute to another digit. 9999 * 9999 has the same number of digits as 4000*4000. The only way to get another digit is 10^4 * 10^4 which is are both n + 1 digit numbers now. Even if you consider a completely random distribution of what you're going to get as a result of multiplication, which it's not, the probability of you not finding a palindrome is astronomically small, and it gets even smaller as n grows. The assumptions don't get weaker, they get even stronger for n > 8. Same goes for starting digits, as n grows, assuming completely random distribution, the chances that you find numbers starting with 999.... become even greater.
For the 3rd one I do not understand why that trivial solution is the answer. When I read it I thought that for two strings "abcefg" "abcxyz" that the answer would be 3, with the subsequences being efg and xyz?
The string itself is a subsequence, so if you have abc and abd, the longest subsequences will be abc and abd, and since the subsequences are different, they can’t be in both
Cool video man. Only 4 weeks into programming but…this is fun to watch and try to understand. I’m starting in Python but I feel like I should be coding in JS. I’ll be lucky if I ever get smart enough to get a UI/UX job let alone an actual web/app dev job. 😅
I solved the first one fine,,, class Solution: def largestPalindrome(self, n: int) -> int: if n == 1: return 9 max_num = 10 ** n - 1 min_num = 10 ** (n - 1) for num in range(max_num, min_num - 1, -1): # Construct a palindrome by joining num with its reverse palindrome = int(str(num) + str(num)[::-1]) # Check if this palindrome can be represented as the product of two n-digit integers for i in range(max_num, int(palindrome ** 0.5) - 1, -1): if palindrome % i == 0 and palindrome // i
3 + years of competitive coding experience, and when this guy is looking for the highest palindrome number from a product...he iterates up from 1 to 1000...instead of down from 1000
I spent 7 hours without giving a break on "Recover a Tree From Preorder Traversal". But I've solved it at the end. My code was over 100 lines, and I even had to force a hashmap to handle duplicate keys. But it was worth it at the end, and it was my first hard question I've solved. So, one hour on a hard question is nothing in my opinion.
Controversial, but I honestly think a lookup table is a totally valid solution to the first problem and I think having an interview question like that is really valuable. Sometimes there just isn't a clever math trick that makes your program 100x faster. In the real world you need to compromise sometimes and saying "We never expect to receive input greater than n so precomputing f(x) for all x
but there is actually a math trick, and he explains in the video someone solved this problem mathematically as it should be. it is not a bad problem, just people did not want to get involved with math.
Colin I love that you’re thinking out loud, keep doing that. Cheers
how about Codeforces Round #815 (Div. 2) today ?
Hey Colin, how are you so good at this? Takes me forever to solve even one question
practice
Brains.
A lot of practice
Probably half asian
Must be pretty good mouse.
Hey Colin, I had a failed attempt to pass an online assessment for Amazon SDE position, and one of the tasks was leetcode # 2281, which is in top 15 with the least acceptance rate. Could you solve and explain it, please?
You updated your browser! So proud of you!
Amazing! Thanks for putting in all the hard work into making these videos! I hope I can be as good of an explainer as you are!
how many years have you been programming in total?
I wonder if your employer would be more impressed to see you solve a difficult problem in less than said minutes versus communicating which would usually take 3x or 5x longer.
Communication is more important. This guy is wasting his time at this point, industry experience is more valuable then solving LC quickly lol
@@anon3501 I mean he (probably) does this for his and our entertainment... Calling it "wasting time" seems a little harsh.
@@FinnBender true, i was just suggesting to build or work on something with his skills versus solving problems that add no value to the world
What you are saying is correct, but he's not doing this for appearing in interviews. People do this stuff for the fun of it too, as a hobby.
@@vishnuvs6121 You shouldn't be taking pride just in things like leet code, its a fun puzzle game but it shouldn't be a major motivator for you. Programmers are solving problems for people or doing something of value for people over what they could be doing
Hi Colin,
For the first problem, the result has to be a palindrome, and apart from n = 1, safe to assume that answer will contain even number of digits. Which means it will be always be divisible by 11. So you can put a condition for one of your numbers to be divisible by 11, only then look for second number possibilities, this will pass leetcodes' time limit.
Edit: Just resumed the video and realized this is already covered :)
Why would the answer have an even number of digits?
@@MichaelSt You're multiplying 2 n digit numbers, presumably starting off with 8 or 9 as their first digit. so something like (8 * 10^(n - 1) + something smaller) * (8 * 10^(n - 1) + something smaller). So 64 * 100^(n - 1) + something small. This is clearly even number of digits.
@@saharshluthra6492 a lot of assumptions there, like the number starting with 8 or 9, and the something small not "overflowing" into the next digit.
I mean you can convince yourself it doesn't happen for 1
@@MichaelSt The something small is < 10^(n - 1) and it physically cannot contribute to another digit. 9999 * 9999 has the same number of digits as 4000*4000. The only way to get another digit is 10^4 * 10^4 which is are both n + 1 digit numbers now.
Even if you consider a completely random distribution of what you're going to get as a result of multiplication, which it's not, the probability of you not finding a palindrome is astronomically small, and it gets even smaller as n grows. The assumptions don't get weaker, they get even stronger for n > 8.
Same goes for starting digits, as n grows, assuming completely random distribution, the chances that you find numbers starting with 999.... become even greater.
Dude Q2 had to feel so good to complete
For the 3rd one I do not understand why that trivial solution is the answer. When I read it I thought that for two strings
"abcefg"
"abcxyz"
that the answer would be 3, with the subsequences being efg and xyz?
The string itself is a subsequence, so if you have abc and abd, the longest subsequences will be abc and abd, and since the subsequences are different, they can’t be in both
@@muddycalendar3292 I'm trying to figure out what implicit condition i was applying to reach my version
The thumbnail is back
For 50k subs, you should speed run eating 50 donuts
Your Background music is very haunting😈
Nice content though.
I do not know why by seeing your thumbnail I feel so good
I learn so much from just watching you code
Cool videos man
Bro can you able to make a tutorial on union find operations on matrix
The real solution to the first largest palindromic product is
n = 2 + (987-2);
Return n;
Ez i don't get why so many dislikes
Cool video man. Only 4 weeks into programming but…this is fun to watch and try to understand.
I’m starting in Python but I feel like I should be coding in JS. I’ll be lucky if I ever get smart enough to get a UI/UX job let alone an actual web/app dev job. 😅
I solved the first one fine,,,
class Solution:
def largestPalindrome(self, n: int) -> int:
if n == 1:
return 9
max_num = 10 ** n - 1
min_num = 10 ** (n - 1)
for num in range(max_num, min_num - 1, -1):
# Construct a palindrome by joining num with its reverse
palindrome = int(str(num) + str(num)[::-1])
# Check if this palindrome can be represented as the product of two n-digit integers
for i in range(max_num, int(palindrome ** 0.5) - 1, -1):
if palindrome % i == 0 and palindrome // i
91 multiplied by a number with "n" digits of 9 is a palindrome but that doesn't help with the question
Why do you mostly use C++ ?
Its efficiency is good for competitive programming
We need more creativity with these thumbnails -- nice vid tho.
Krita and bloons TD 6🔥
Its ironic how he is a competitive programmer but used someone else's code to find the questions
cute boymoder
Leetcode 862
ur so cute >_
3 + years of competitive coding experience, and when this guy is looking for the highest palindrome number from a product...he iterates up from 1 to 1000...instead of down from 1000
(high - i) * (high - j) means nothing to you?
@@Splish_Splash lol
💥💥💥💥💥💥
Your voice is not coming
You guys are spending 1 hour on hard questions, i though medium takes that much 👀