Count Ways to Build Good Strings - Leetcode 2466 - Python

  Рет қаралды 7,773

NeetCodeIO

NeetCodeIO

Күн бұрын

Solving Leetcode 2466 - Count Ways to build Good strings, today's daily leetcode problem on May 12.
🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
Problem Link: leetcode.com/problems/count-w...
0:00 - Read the problem
0:30 - Intuition
2:50 - Explaining Decision Tree
7:48 - Coding Memoization
10:40 - Coding Tabulation
leetcode 2466
#neetcode #leetcode #python

Пікірлер: 22
@uptwist2260
@uptwist2260 Жыл бұрын
thanks for the daily
@anand.prasad502
@anand.prasad502 Жыл бұрын
3:18 Ans is "NO", it is length of string not the string, so it can be different. "000" and "100" result can be different;
@deadlyecho
@deadlyecho Жыл бұрын
Can we solve using a combinatorics approach ?
@rowanus116
@rowanus116 2 ай бұрын
regardless of previous string formulation as long as they have the same length, the decision is the same, either choose 0 or 1, that's why caches work here.
@abaddon6206
@abaddon6206 Жыл бұрын
Can we do this problem using brute force and applying permutation and combination. Because in this problem all we have to find is the combination of the good string?
@aniketmahangare8333
@aniketmahangare8333 Жыл бұрын
Thank you so much man.
@shubhaverma5697
@shubhaverma5697 21 күн бұрын
i think my mind broke when you went from backtracking to linked list lol
@MP-ny3ep
@MP-ny3ep Жыл бұрын
Thank you!
@DavidDLee
@DavidDLee Жыл бұрын
If you go backwards in the iterative solution, the result is dp[0]. However, you can't just set dp[high] = 1 and keep everything else 0. Also, in the general case, max(dp[low:high + 1]) might be > 1.
@kaushik.aryan04
@kaushik.aryan04 Жыл бұрын
This was a really good question
@krateskim4169
@krateskim4169 Жыл бұрын
Thank you so much
@ronbuchanan5432
@ronbuchanan5432 Жыл бұрын
What's the time complexity?
@ouchlock
@ouchlock Жыл бұрын
spent an hour with permutation approach, and it turned out to be so simple, muahh %(
@blazze_
@blazze_ Жыл бұрын
Bro is so emotional when explaining the problem.
@TheNishant30
@TheNishant30 7 ай бұрын
one of the test cases blows up the javascript stack even with memoization. low is 100000, high is 100000, zero is 2 and one is 8.
@arpanbanerjee6224
@arpanbanerjee6224 Жыл бұрын
Great exoplanation as usual- java solution class Solution { Integer[] dp = null; int mod= 1000000007; private int helper(int low, int high, int zero, int one, int currLen){ if(currLen>high) return 0; if(dp[currLen]!=null) return dp[currLen]; int res=0; // if within range we wll include this string if(currLen>=low){ res=1; }else{ res=0; } res+= helper(low,high,zero,one,currLen+zero)%mod +helper(low,high,zero,one,currLen+one)%mod; dp[currLen]=res%mod; return dp[currLen]; } public int countGoodStrings(int low, int high, int zero, int one) { dp=new Integer[high+1]; return helper(low,high,zero,one,0); } }
@sandeepmourya8922
@sandeepmourya8922 Жыл бұрын
Hey NeetCode or anyone reading this, I really need your help I cannot find single resource for good explanation of this problem: 2673. Make Costs of Paths Equal in a Binary Tree (It has no editorial on Leetcode) Everyone has almost used the same solution int minIncrements(int n, vector& cost) { int res = 0; function dfs = [&](int i) { if (i >= cost.size()) return 0; int a = dfs(2 * i + 1), b = dfs(2 * i + 2); res += abs(a - b); return cost[i] + max(a, b); }; dfs(0); return res; } But NOOOOO one explains clearly whyy do we have to return cost[i] + max(a, b). Any help from anyone in the comments section will be appreciated.
@kaushik.aryan04
@kaushik.aryan04 Жыл бұрын
You explained it really well but the code in python is very different when compared to java or c++ This is my code in java ( tabulation) class Solution { int mod = 1000000007; int[] dp ; public int countGoodStrings(int low, int high, int zero, int one) { dp = new int[high + Math.max(high , low) + 5]; // filling base case array for(int i = 0 ; i < high + 5 ; i++){ if(i >= low && i high) dp[i] = 0; } for(int i = high ; i >= 0 ; i--){ int left = dp[i+ zero] % mod; int right = dp[i + one] % mod; dp[i] = dp[i]+ (left+ right) % mod; } return dp[0]; } }
@mohdmaaz6651
@mohdmaaz6651 Жыл бұрын
Java Solution using HashMap: public int countGoodStrings(int low, int high, int zero, int one) { int mod = (int) 1e9+7; HashMap dp = new HashMap(); for(int i=high; i>=0; --i){ if(i>=low) dp.put(i, (1+dp.getOrDefault(i+zero, 0)+dp.getOrDefault(i+one, 0))%mod); else dp.put(i, (dp.getOrDefault(i+zero, 0)+dp.getOrDefault(i+one, 0))%mod); } return dp.get(0); }
@amalvijay8222
@amalvijay8222 Жыл бұрын
1st comment and big fan
@GameFlife
@GameFlife Жыл бұрын
bruh say feel good until tmr xDD
@name_surname_1337
@name_surname_1337 8 ай бұрын
do you know that fb doesn't ask DP at all? stop doing these fake thumbnails pls
Uncrossed Lines - Leetcode 1035 - Python
29:14
NeetCodeIO
Рет қаралды 8 М.
Stone Game II - Leetcode 1140 - Python
18:40
NeetCodeIO
Рет қаралды 11 М.
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 18 МЛН
Дарю Самокат Скейтеру !
00:42
Vlad Samokatchik
Рет қаралды 8 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 1,6 МЛН
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
Largest Color Value in a Directed Graph - Leetcode 1857 - Python
22:11
Crowdstruck (Windows Outage) - Computerphile
14:42
Computerphile
Рет қаралды 123 М.
F-strings In Python: Everything You Need To Know
23:29
ArjanCodes
Рет қаралды 49 М.
Dota2 Senate - Leetcode 649 - Python
14:48
NeetCodeIO
Рет қаралды 19 М.
Is Graph Bipartite? - Leetcode 785 - Python
11:17
NeetCodeIO
Рет қаралды 14 М.
Ones and Zeroes - Leetcode 474 - Python
17:59
NeetCodeIO
Рет қаралды 10 М.
Best Team with no Conflicts - Leetcode 1626 - Python
14:03
NeetCodeIO
Рет қаралды 8 М.
Last Stone Weight II - Leetcode 1049 - Python
19:04
NeetCodeIO
Рет қаралды 13 М.
number of good ways to split a string leetcode | leetcode 1525
9:09
Longest String Chain - Leetcode 1048 - Python
15:34
NeetCodeIO
Рет қаралды 8 М.
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 18 МЛН