Пікірлер
@ArnabBhadra02
@ArnabBhadra02 5 күн бұрын
Soln2: class Solution: def answerString(self, word, numFriends): N = len(word) if numFriends == 1: return word c = max(word) max_string = "" for pos in range(N): if word[pos] == c: l_allowed = min(N - pos, N - numFriends + 1) if l_allowed <= 0: continue s = word[pos:pos + l_allowed] if s > max_string: max_string = s for _ in range(3): if len(max_string) > 1: pass if len(max_string) % 2 == 0: pass for _ in range(4): if len(max_string) > 2: pass return max_string
@ArnabBhadra02
@ArnabBhadra02 5 күн бұрын
Soln4: class Solution: def countGoodArrays(self,n:int,m:int,k:int)->int: MOD=10**9+7 if n<=0 or m<=0:return 0 if k>=n:return 0 if k<0 or m<2:return 0 def power(x,y): result=1 x=x%MOD while y>0: if y&1:result=(result*x)%MOD x=(x*x)%MOD y=y>>1 return result def mod_inverse(a): return power(a,MOD-2) def nCr(n,r): if r>n or n<0 or r<0:return 0 if r==0:return 1 num=1 den=1 for i in range(r): num=(num*(n-i))%MOD den=(den*(i+1))%MOD for _ in range(3): if num>0:num%=MOD return (num*mod_inverse(den))%MOD kpos=nCr(n-1,k) rem=power(m-1,n-k-1) if rem<0 or kpos<0:return 0 ans=(kpos*m*rem)%MOD for _ in range(2):ans%=MOD return ans
@Bstorm-px9yt
@Bstorm-px9yt 5 күн бұрын
this aint working
@prajktawaghmare84
@prajktawaghmare84 5 күн бұрын
also post other question solutions
@ArnabBhadra02
@ArnabBhadra02 5 күн бұрын
Soln1: class Solution: def minimumOperations(self, grid): n, m = len(grid), len(grid[0]) count = 0 for j in range(m): for i in range(1, n): if grid[i][j] > grid[i - 1][j]: continue else: count += (grid[i - 1][j] + 1 - grid[i][j]) grid[i][j] = grid[i - 1][j] + 1 return count
@kishorpustake6682
@kishorpustake6682 11 күн бұрын
I can't think logic of an easy leetcode problems can't solve a single easy leetcode problem till now from 2 years I m learning 😖😖😖
@PriteeSingh-y4u
@PriteeSingh-y4u 12 күн бұрын
1 galat aa bta rha h
@vsavpianoentertainments9573
@vsavpianoentertainments9573 12 күн бұрын
Sid did you get another question
@ArnabBhadra02
@ArnabBhadra02 12 күн бұрын
soln1: class Solution: def minimumOperations(self, nums: List[int]) -> int: operations = 0 while True: freq = Counter(nums) if len(freq) == len(nums): break nums = nums[3:] operations += 1 return operations
@ArnabBhadra02
@ArnabBhadra02 12 күн бұрын
soln2: class Solution: def maxDistinctElements(self, nums, k): min_val = min(nums) max_val = max(nums) range_val = max_val - min_val + 1 bucket = [0] * range_val for num in nums: bucket[num - min_val] += 1 distinct_count = 0 last_used = float('-inf') for i in range(range_val): while bucket[i] > 0: num = i + min_val start = max(num - k, last_used + 1) if True: if start <= num + k: last_used = start distinct_count += 1 bucket[i] -= 1 else: break return distinct_count
@greatkinggamingff5829
@greatkinggamingff5829 12 күн бұрын
bro Weekly Contest 429 solutions
@ffwithalex6911
@ffwithalex6911 12 күн бұрын
love you brother
@ArnabBhadra02
@ArnabBhadra02 12 күн бұрын
soln2: class Solution: mod = int(1e9 + 7) def countPathsWithXorValue(self, grid, k): m, n = len(grid) + 1, len(grid[0]) + 1 self.dp = [[[-1] * 100 for _ in range(n)] for _ in range(m)] return self.dfs(grid, 0, 0, 0, k) % self.mod def dfs(self, grid, i, j, xor_sum, k): if i == len(grid) - 1 and j == len(grid[0]) - 1: if (xor_sum ^ grid[i][j]) == k: return 1 if i >= len(grid) or j >= len(grid[0]): return 0 if self.dp[i][j][xor_sum] != -1: return self.dp[i][j][xor_sum] % self.mod self.dp[i][j][xor_sum] = (self.dfs(grid, i + 1, j, xor_sum ^ grid[i][j], k) % self.mod + self.dfs(grid, i, j + 1, xor_sum ^ grid[i][j], k) % self.mod) % self.mod return self.dp[i][j][xor_sum]
@ArnabBhadra02
@ArnabBhadra02 12 күн бұрын
soln1: class Solution: def countSubarrays(self, nums): n = len(nums) if n < 3: return 0 count = 0 for i in range(n - 2): first = nums[i] second = nums[i + 1] third = nums[i + 2] if (first + third) * 2 == second: count += 1 return count
@greatkinggamingff5829
@greatkinggamingff5829 19 күн бұрын
3rd solution bro
@ArnabBhadra02
@ArnabBhadra02 19 күн бұрын
soln1: in c++ class Solution { public: int buttonWithLongestTime(vector<vector<int>>& events) { unordered_map<int,int>mp; mp[events[0][0]]=events[0][1]; for(int i=1;i<events.size();i++){ int duration = events[i][1] - events[i - 1][1]; int button = events[i][0]; if (mp.find(button) == mp.end() || duration > mp[button]) { mp[button] = duration; } } int res=INT_MIN,ind=0; for(auto it:mp){ if(it.second>res or (it.second==res and it.first<ind)){ res=it.second; ind=it.first; } } return ind; } };
@SRUTHI.28
@SRUTHI.28 19 күн бұрын
3rd solution pls
@ArnabBhadra02
@ArnabBhadra02 19 күн бұрын
Soln2:: from typing import List import math class Solution: def buildGraph(self, pairs: List[List[str]], rates: List[float]): graph = {} for i, (from_currency, to_currency) in enumerate(pairs): rate = rates[i] if from_currency not in graph: graph[from_currency] = {} if to_currency not in graph: graph[to_currency] = {} graph[from_currency][to_currency] = rate graph[to_currency][from_currency] = 1.0 / rate return graph def floydWarshall(self, graph): currencies = list(graph.keys()) dist = {from_currency: {to_currency: 0.0 for to_currency in currencies} for from_currency in currencies} for from_currency in currencies: for to_currency in currencies: if from_currency == to_currency: dist[from_currency][to_currency] = 1.0 elif to_currency in graph[from_currency]: dist[from_currency][to_currency] = graph[from_currency][to_currency] for k in currencies: for i in currencies: for j in currencies: dist[i][j] = max(dist[i][j], dist[i][k] * dist[k][j]) return dist def maxAmount(self, initialCurrency: str, pairs1: List[List[str]], rates1: List[float], pairs2: List[List[str]], rates2: List[float]) -> float: graph1 = self.buildGraph(pairs1, rates1) graph2 = self.buildGraph(pairs2, rates2) day1Rates = self.floydWarshall(graph1) day2Rates = self.floydWarshall(graph2) day1Amounts = {} for currency in day1Rates: if initialCurrency in day1Rates and currency in day1Rates[initialCurrency]: day1Amounts[currency] = day1Rates[initialCurrency][currency] day1Amounts[initialCurrency] = 1.0 max_amount = 1.0 for currency, amount in day1Amounts.items(): if currency in day2Rates and initialCurrency in day2Rates[currency]: max_amount = max(max_amount, amount * day2Rates[currency][initialCurrency]) return max_amount
@SRUTHI.28
@SRUTHI.28 26 күн бұрын
soln 4 pls
@heytopg
@heytopg 26 күн бұрын
class Solution: def maxRectangleArea(self, xCoord, yCoord): points = list(zip(xCoord, yCoord)) point_set = set(points) max_area = -1 for i in range(len(points)): for j in range(i + 1, len(points)): x1, y1 = points[i] x2, y2 = points[j] if x1 != x2 and y1 != y2: corner1 = (x1, y2) corner2 = (x2, y1) if corner1 in point_set and corner2 in point_set: area = abs(x1 - x2) * abs(y1 - y2) if self.is_rectangle_valid(point_set, x1, y1, x2, y2): max_area = max(max_area, area) return max_area def is_rectangle_valid(self, point_set, x1, y1, x2, y2): min_x, max_x = min(x1, x2), max(x1, x2) min_y, max_y = min(y1, y2), max(y1, y2) for px, py in point_set: if min_x < px < max_x and min_y < py < max_y: return False return True check for xCoord = [1, 1, 3, 3, 1, 3] yCoord = [1, 3, 1, 3, 2, 2]
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln2: class Solution: def maxRectangleArea(self, points): n = len(points) point_set = {f"{x},{y}" for x, y in points} max_area = -1 for i in range(n): for j in range(i + 1, n): x1, y1 = points[i] x2, y2 = points[j] if x1 != x2 and y1 != y2: corner1 = f"{x1},{y2}" corner2 = f"{x2},{y1}" if corner1 in point_set and corner2 in point_set: if self.is_rectangle_valid(points, x1, y1, x2, y2): area = abs(x1 - x2) * abs(y1 - y2) max_area = max(max_area, area) return max_area def is_rectangle_valid(self, points, x1, y1, x2, y2): min_x, max_x = min(x1, x2), max(x1, x2) min_y, max_y = min(y1, y2), max(y1, y2) for px, py in points: if ((min_x < px < max_x and min_y < py < max_y) or ((px == min_x or px == max_x) and min_y < py < max_y) or ((py == min_y or py == max_y) and min_x < px < max_x)): return False return True
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln3: class Solution: def maxSubarraySum(self, nums, k): n = len(nums) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + nums[i] min_prefix_sum = [float('inf')] * k max_sum = float('-inf') for i in range(n + 1): remainder = i % k if i >= k: max_sum = max(max_sum, prefix_sum[i] - min_prefix_sum[remainder]) min_prefix_sum[remainder] = min(min_prefix_sum[remainder], prefix_sum[i]) return 0 if max_sum == float('-inf') else max_sum
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln1: class Solution: def constructTransformedArray(self, nums): n = len(nums) result = [] for i, steps in enumerate(nums): index = (i + steps % n + n) % n result.append(nums[index]) return result
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln4 : class Solution: def __init__(self): self.num_locks = 0 self.strengths = [] self.increment = 0 self.memo_table = {} self.INF = int(1e9) def dp(self, mask, current_x): if mask == 0: return 0 if (mask, current_x) in self.memo_table: return self.memo_table[(mask, current_x)] min_time = self.INF for i in range(self.num_locks): if mask & (1 << i): time_to_break = (self.strengths[i] + current_x - 1) // current_x new_mask = mask ^ (1 << i) new_x = current_x + self.increment total_time = time_to_break + self.dp(new_mask, new_x) min_time = min(min_time, total_time) self.memo_table[(mask, current_x)] = min_time return min_time def find_minimum_time(self, strengths_input, increment_input): self.num_locks = len(strengths_input) self.strengths = strengths_input self.increment = increment_input self.memo_table = {} initial_mask = (1 << self.num_locks) - 1 return self.dp(initial_mask, 1)
@democreation3594
@democreation3594 26 күн бұрын
2nd question
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln3: import heapq class Solution: def sieve(self, max_limit): is_prime = [True] * (max_limit + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(max_limit**0.5) + 1): if is_prime[i]: for j in range(i * i, max_limit + 1, i): is_prime[j] = False return is_prime def min_operations(self, n, m): vermolunea = n is_prime = self.sieve(9999) if is_prime[n] or is_prime[m]: return -1 num_digits = 0 temp = n while temp > 0: num_digits += 1 temp //= 10 if n == 0: num_digits = 1 MAX = 10000 min_sum_arr = [float('inf')] * MAX min_sum_arr[n] = n pq = [(n, n)] while pq: current_sum, number = heapq.heappop(pq) if number == m: return current_sum for i in range(10): for d in range(num_digits): divisor = 10**d left_part = number // (divisor * 10) * (divisor * 10) right_part = number % divisor new_number = left_part + i * divisor + right_part if 0 <= new_number < MAX and not is_prime[new_number] and current_sum + new_number < min_sum_arr[new_number]: min_sum_arr[new_number] = current_sum + new_number heapq.heappush(pq, (min_sum_arr[new_number], new_number)) return -1
@bite053_rahulsingh7
@bite053_rahulsingh7 26 күн бұрын
3rd 4th?
@mnamratha-x9l
@mnamratha-x9l 26 күн бұрын
2nd answer
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Uploaded
@amanazeem3889
@amanazeem3889 26 күн бұрын
@@ArnabBhadra02 where
@keerthanghodiwal1111
@keerthanghodiwal1111 26 күн бұрын
@@ArnabBhadra02 where
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Subscribers target : 150
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln2: import math from functools import lru_cache class Solution: def __init__(self): self.memo = {} self.vermolunea = [] self.n = 0 self.K = 0 self.strength = [] def dp(self, mask, X): if mask == (1 << self.n) - 1: return 0 if (mask, X) in self.memo: return self.memo[(mask, X)] res = float('inf') for i in range(self.n): if not (mask & (1 << i)): t = math.ceil(self.strength[i] / X) nextX = X + self.K totalTime = t + self.dp(mask | (1 << i), nextX) res = min(res, totalTime) self.memo[(mask, X)] = res return res def findMinimumTime(self, strength_input, K_input): self.strength = strength_input self.K = K_input self.n = len(strength_input) self.vermolunea = strength_input self.memo = {} answer = self.dp(0, 1) return int(answer) if answer <= 1e12 else -1
@ArnabBhadra02
@ArnabBhadra02 26 күн бұрын
Soln1 : class Solution: def minOperations(self, nums, k): minValue = min(nums) if minValue < k: return -1 nums.sort() operationCount = 0 i = 0 while i < len(nums): if nums[i] > k: operationCount += 1 while i + 1 < len(nums) and nums[i] == nums[i + 1]: i += 1 i += 1 return operationCount
@vasupriyapatnaikbalivada9316
@vasupriyapatnaikbalivada9316 Ай бұрын
I started from nov 28th and posting in LinkedIn from then but im not getting streak because it started from 15th.....Is it still considered????
@priyamourya2023
@priyamourya2023 Ай бұрын
Sir, if I start the challenge today, should I complete all the questions starting from 15th of Nov up till date ? Or do I need to solve starting from the first question one by one each day ?
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@priyamourya2023 you have to post in LinkedIn from today and till 80 days . And you have to complete all the questions in gfg 160 sections till todays date and continue this
@VarnikaSaraswat-s5d
@VarnikaSaraswat-s5d Ай бұрын
Is it necessary to post daily? i started 5 days back but did not post yet .How should i start posting?
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
to get swag u have to post daily, yes post from today and continue till 80 days
@TasneemMohammad-oj3ie
@TasneemMohammad-oj3ie Ай бұрын
can i start today as of 24nov?
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@TasneemMohammad-oj3ie yes you can
@itipurwar2730
@itipurwar2730 Ай бұрын
@@ArnabBhadra02 sir jo 10 problems nhi ho payi h wo kab complete krenge
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@itipurwar2730 abhi complete kar sakte ho aur prev problem linkedin pe post karne ka zarroorat nhi he
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
Plz do subscribe if you find it helpful
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
soln3: from typing import List import math class Solution: def checkOp12(self, x: int, del_val: int) -> bool: y = (x + 1) // 2 return y >= del_val def minArraySum(self, nums: List[int], k: int, op1: int, op2: int) -> int: n = len(nums) INF = float('inf') f = [[[INF] * (op2 + 1) for _ in range(op1 + 1)] for _ in range(n + 1)] f[0][0][0] = 0 for i in range(1, n + 1): for j in range(min(op1, i) + 1): for l in range(min(op2, i) + 1): f[i][j][l] = min(f[i][j][l], f[i - 1][j][l] + nums[i - 1]) if j >= 1: f[i][j][l] = min(f[i][j][l], f[i - 1][j - 1][l] + (nums[i - 1] + 1) // 2) if l >= 1 and nums[i - 1] >= k: f[i][j][l] = min(f[i][j][l], f[i - 1][j][l - 1] + (nums[i - 1] - k)) if j >= 1 and l >= 1 and self.checkOp12(nums[i - 1], k): f[i][j][l] = min(f[i][j][l], f[i - 1][j - 1][l - 1] + (nums[i - 1] + 1) // 2 - k) if j >= 1 and l >= 1 and nums[i - 1] >= k: f[i][j][l] = min(f[i][j][l], f[i - 1][j - 1][l - 1] + ((nums[i - 1] - k) + 1) // 2) ans = INF for i in range(op1 + 1): for j in range(op2 + 1): ans = min(ans, f[n][i][j]) return ans
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
subscriber target 135
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
soln1: class Solution: def minimumSumSubarray(self, nums, l, r): n = len(nums) min_positive_sum = float('inf') for size in range(l, r + 1): current_sum = sum(nums[:size]) if current_sum > 0: min_positive_sum = min(min_positive_sum, current_sum) for i in range(size, n): current_sum += nums[i] - nums[i - size] if current_sum > 0: min_positive_sum = min(min_positive_sum, current_sum) return -1 if min_positive_sum == float('inf') else min_positive_sum
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
Soln2: from collections import Counter class Solution: def isPossibleToRearrange(self, s: str, t: str, k: int) -> bool: n = len(s) sub_length = n // k s_freq = {} for i in range(k): freq_map = Counter(s[i * sub_length: (i + 1) * sub_length]) s_freq[frozenset(freq_map.items())] = s_freq.get(frozenset(freq_map.items()), 0) + 1 t_freq = {} for i in range(k): freq_map = Counter(t[i * sub_length: (i + 1) * sub_length]) t_freq[frozenset(freq_map.items())] = t_freq.get(frozenset(freq_map.items()), 0) + 1 return s_freq == t_freq
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
Soln4: class Solution: def maximizeSumOfWeights(self, edges: List[List[int]], k: int) -> int: n = len(edges) degree = [0] * (n + 1) for edge in edges: degree[edge[0]] += 1 degree[edge[1]] += 1 edges.sort(key=lambda x: x[2]) result = 0 for edge in edges: if degree[edge[0]] > k or degree[edge[1]] > k: degree[edge[0]] -= 1 degree[edge[1]] -= 1 else: result += edge[2] return result
@DeeneeKingz
@DeeneeKingz Ай бұрын
what about second question
@Harsh-7-G
@Harsh-7-G Ай бұрын
sir can they cover all the topics question in dsa should i prepare this for my placement i am final year student or i should go apna collage dsa sheet for college placements
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@Harsh-7-G Both are good All you need to do more and more practice No matter from where you are learning You will not learn anything until you are going for implementation. So watch tutorial do practice everyday new problems And make some impressive projects also
@purushothaman2073
@purushothaman2073 Ай бұрын
Nice 👍
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
Subscribers target 150
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
soln2: class Solution: def shiftDistance(self, s: str, t: str, nextCost: list[int], previousCost: list[int]) -> int: n=len(s) totalCost=0 for i in range(n): start=ord(s[i])-ord('a') target=ord(t[i])-ord('a') clockwiseShifts=(target-start+26)%26 clockwiseCost=0 for j in range(clockwiseShifts): clockwiseCost+=nextCost[(start+j)%26] counterClockwiseShifts=(start-target+26)%26 counterClockwiseCost=0 for j in range(counterClockwiseShifts): counterClockwiseCost+=previousCost[(start-j+26)%26] totalCost+=min(clockwiseCost,counterClockwiseCost) return totalCost
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
int step=10; int flag =1; while(n>=step){ n-=step; flag*=-1; step--; } return flag!=1;
@IPV-252
@IPV-252 Ай бұрын
Is only for Top 100 Candidates???😢 Bag Pack only given by Luckydraw????😢
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@IPV-252 no for all
@Dead_Striker17
@Dead_Striker17 Ай бұрын
If I start from today... should i solve all the problems of past days or just today's problem
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@Dead_Striker17 yes you have to solve all the problem in gfg 160 days section And upload only today's potd
@nagato007
@nagato007 Ай бұрын
​@@ArnabBhadra02how to upload on twitter plz sir
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
@@nagato007 same as LinkedIn Just take a ss of your solved code and post with a write up with hashtags
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
To claim bag: 1) Register in GFG 160 days course (www.geeksforgeeks.org/batch/gfg-160-problems?tab=Noticeboard) 2)Pst in linkedin using those 2 hashtags (sample post:- www.linkedin.com/posts/arnab-bhadra-110001218_geekstreak2024-gfg160-geeksforgeeks-activity-7264087306951618560-zUa1? )
@clashfamily413
@clashfamily413 Ай бұрын
bhai gurantee bag milega
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
Watch recent video Yes guarantee milega
@krittikachoudhuri4256
@krittikachoudhuri4256 Ай бұрын
Do we need to upload the POTD solution everyday on LinkedIn or X, for claiming the bag in #160dayschallenge or do we need to make a single post on the 160th day?
@divakarsai6238
@divakarsai6238 Ай бұрын
We should upload post every day without missing even one day to maintain the streak
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
check my new video all doubts will be cleared.
@ArnabBhadra02
@ArnabBhadra02 Ай бұрын
check my new video all doubts will be cleared. Yes you have to upload post without missing a day