#Day 7 of solving 450 questions[25/450]

Day 7 : March 26,2022
Problems solved today :

Rearrange positive and negative numbers in O(n) time and O(1) extra space

*Tried many approaches but this made a lot of sense to me.

subarray-sum-equals-k

-Logic :
1) sum all the elements from start: prefix sum
2)store prefix sum inside dictionary
* if prefixsum not in dictionary: dict[prefixsum]=1
* else : increase the dictionary[key] +=1
3)Now check for K-prefixsum in dict , if exist increase your count.

Factorial of Very large number

  • Couldn’t find any linear solution. 5 OPTIONS: a)iterative approach : fact = fact*i b)Recursive : n or n*fact(n-1) c)Math factorial function d)lgamma library function e)Ramanujan’s factorial approximation

array-subset-of-another-array

  • a)HashMap should be the best approach(lookup in linear time) OR b)for arr1 in arr2: count +=1 , if(count = len(arr2): Pass.

229.Majority Element II

maximum-product-subarray

Thoughts:

Finally starting to get in flow and actually thinking about the problem not the code.

原文链接:#Day 7 of solving 450 questions[25/450]

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
If you hold tight, how can a free hand to hug now?
你若将过去抱的太紧,怎么能腾出手来拥抱现在?
评论 抢沙发

请登录后发表评论

    暂无评论内容