General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Samurai Josh
NeetCode
comments
Comments by "Samurai Josh" (@samuraijosh1595) on "NeetCode" channel.
Previous
1
Next
...
All
you cant leave us hanging like that after droppping this bomb. explain how it could be solved in O(n) time.
3
yeah the code based on the combinatorics seems to work but i dont get what the fuck is combinatorics doing here at all. i wonder if youve figured it out?
2
ok now i got why we multiply them. firslty, a small correction for f (5) we have f(3) on the left and f(1) on the right subtree only for root node 4. {1, 2, 3} --- 4 --- {5 } now {1, 2, 3} can be arranged in how many unique trees is calculated by f(3) and so is {5} calculated. we get f(3) = 5, f(1) = 1. good. this is a simple case to explain where we have unique three things of one kind and 1 thing of another kind. so there's only three ways to arrange these two togetehr wohtout reptions such that they both get exist at the same time. if we take a case like f(3) on the left and f(2) on the right: we have three blue balls and 2 red balls. how would you arrange 3 blue balls with 2 red balls wihtout reptitions? 3 * 2 = 6 is the way to do it.
2
But this is not O(1) space solution???
2
@cck4978 but this is slow, an equality operation of two whole dictionaries is not fast
2
in haskell: import Data.List permute :: Eq a => [a] -> [[a]] permute [] = [[]] permute xs = [x : ys | x <- xs, ys <- permute (delete x xs)] based on that in python: def delete(x, xs): return [e for e in xs if e != x] def permute(nums): if not nums: return [[]] else: return [[x] + ys for x in nums for ys in permute(delete(x, nums))]
2
cant we do the same for height[right] < height[left]? moving the right pointer backwards until we find the new valid right index? isnt' a simple arithmetic calculation very negligible in terms of cost?
2
@akarshanmishra2351 what's his ethnicity?
2
ugly monstrosity
1
@jason1666 most elegant solution: in haskell: import Data.List permute :: Eq a => [a] -> [[a]] permute [] = [[]] permute xs = [x : ys | x <- xs, ys <- permute (delete x xs)] based on that in python: def delete(x, xs): return [e for e in xs if e != x] def permute(nums): if not nums: return [[]] else: return [[x] + ys for x in nums for ys in permute(delete(x, nums))]
1
this will not work for this case: s1="adc" s2="dcda"
1
@Grawlix99 yeah lol I was wrong
1
in haskell: import Data.List permute :: Eq a => [a] -> [[a]] permute [] = [[]] permute xs = [x : ys | x <- xs, ys <- permute (delete x xs)] based on that in python: def delete(x, xs): return [e for e in xs if e != x] def permute(nums): if not nums: return [[]] else: return [[x] + ys for x in nums for ys in permute(delete(x, nums))]
1
@vadimkokielov2173 wheres the code, you liar.
1
@thezendawg even faster?
1
Previous
1
Next
...
All