DevVortex (@dev_vortex_) 's Twitter Profile
DevVortex

@dev_vortex_

#Full Stack Development | MERN | NextJs | Typescript | Python | OpenAI | BuildInPublic | Open Source | #100DaysOfCode

ID: 1618577385758298113

calendar_today26-01-2023 11:51:54

2,2K Tweet

587 Followers

243 Following

DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 43) βœ… Construct String With Repeat Limit πŸ’‘ Approach (Heap) 1️⃣ Count character frequencies 2️⃣ Use a max-heap to pick the largest char 3️⃣ Append up to repeatLimit times 4️⃣ If chars remain, use the next largest char, then push back unused chars

πŸš€ #LeetCode POTD (Day 43) βœ…
Construct String With Repeat Limit

πŸ’‘ Approach (Heap)

1️⃣ Count character frequencies
2️⃣ Use a max-heap to pick the largest char
3️⃣ Append up to repeatLimit times
4️⃣ If chars remain, use the next largest char, then push back unused chars
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 44) βœ… Final Prices With Special Discount πŸ’‘ Approach (Stack) 1️⃣ Traverse prices in reverse 2️⃣ Use stack to find nearest smaller price to right 3️⃣ Discount: prices[i] - stack.top() or prices[i] 4️⃣ Push current price onto stack

πŸš€ #LeetCode POTD (Day 44) βœ…
Final Prices With Special Discount

πŸ’‘ Approach (Stack)

1️⃣ Traverse prices in reverse
2️⃣ Use stack to find nearest smaller price to right
3️⃣ Discount: prices[i] - stack.top() or prices[i]
4️⃣ Push current price onto stack
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 45) βœ… Max Chunks To Make Sorted πŸ’‘ Approach 1️⃣ Track curr_max while iterating. 2️⃣ If curr_max == i, it’s a valid chunk end. 3️⃣ Increment chunk count and return total.

πŸš€ #LeetCode POTD (Day 45) βœ…

Max Chunks To Make Sorted

πŸ’‘ Approach

1️⃣ Track curr_max while iterating.
2️⃣ If curr_max == i, it’s a valid chunk end.
3️⃣ Increment chunk count and return total.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 47) βœ… Maximum Number of K-Divisible Components πŸ’‘ Approach (DFS) 1️⃣ Perform a DFS traversal to compute subtree sums. 2️⃣ If a subtree sum is divisible by k, it forms a valid component. 3️⃣ Increment component count (ans) and reset sum for that subtree.

πŸš€ #LeetCode POTD (Day 47) βœ…
Maximum Number of K-Divisible Components

πŸ’‘ Approach (DFS)

1️⃣ Perform a DFS traversal to compute subtree sums.
2️⃣ If a subtree sum is divisible by k, it forms a valid component.
3️⃣ Increment component count (ans) and reset sum for that subtree.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 50) βœ… Find Minimum Diameter After Merging Two Trees πŸ’‘ Approach (BFS) 1️⃣ Compute diameters (d1, d2) of both trees using BFS. 2️⃣ Merged diameter: max(d1, d2, ⌈d1/2βŒ‰ + ⌈d2/2βŒ‰ + 1). 3️⃣ BFS twice finds the farthest nodes to calculate tree diameter.

πŸš€ #LeetCode POTD (Day 50) βœ…
Find Minimum Diameter After Merging Two Trees

πŸ’‘ Approach (BFS)

1️⃣ Compute diameters (d1, d2) of both trees using BFS.
2️⃣ Merged diameter: max(d1, d2, ⌈d1/2βŒ‰ + ⌈d2/2βŒ‰ + 1).
3️⃣ BFS twice finds the farthest nodes to calculate tree diameter.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 51) βœ… Find Largest Value in Each Tree Row πŸ’‘ Approach (Simple BFS) 1️⃣ Apply plain BFS to traverse the tree level by level. 2️⃣ At each level, store the maximum value in the result vector.

πŸš€ #LeetCode POTD (Day 51) βœ…

Find Largest Value in Each Tree Row

πŸ’‘ Approach (Simple BFS)

1️⃣ Apply plain BFS to traverse the tree level by level.
2️⃣ At each level, store the maximum value in the result vector.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 52) βœ… Target Sum πŸ’‘ Approach (DP) 1️⃣ Use recursion with memoization to explore adding/subtracting nums[ind]. 2️⃣ Handle negatives by offsetting currSum with S = sum(nums). 3️⃣ Store results in dp[ind][currSum + S] to avoid recomputation and optimize.

πŸš€ #LeetCode POTD (Day 52) βœ…

Target Sum

πŸ’‘ Approach (DP)

1️⃣ Use recursion with memoization to explore adding/subtracting nums[ind].
2️⃣ Handle negatives by offsetting currSum with S = sum(nums).
3️⃣ Store results in dp[ind][currSum + S] to avoid recomputation and optimize.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 55) βœ… πŸ’‘ Approach (Dynamic Programming) 1️⃣ Precompute freq for char counts at each column in words 2️⃣ Use recursion + memoization to find ways to form target[i] starting from column j 3️⃣ Either skip or use column j, ensuring results are modulo 1e9 + 7

πŸš€ #LeetCode POTD (Day 55) βœ…

πŸ’‘ Approach (Dynamic Programming)

1️⃣ Precompute freq for char counts at each column in words
2️⃣ Use recursion + memoization to find ways to form target[i] starting from column j
3️⃣ Either skip or use column j, ensuring results are modulo 1e9 + 7
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 56) βœ… πŸ’‘ Approach (Dynamic Programming) 1️⃣ Start recursion with curr_len = 0, check bounds [low, high], set addOne = true if valid 2️⃣ Count ways via recursive calls for take_one & take_zero 3️⃣ Return addOne + take_one + take_zero (total ways)

πŸš€ #LeetCode POTD (Day 56) βœ…

πŸ’‘ Approach (Dynamic Programming)

1️⃣ Start recursion with curr_len = 0, check bounds [low, high], set addOne = true if valid

2️⃣ Count ways via recursive calls for take_one & take_zero

3️⃣ Return addOne + take_one + take_zero (total ways)
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 59) βœ… Count Vowel Strings in Ranges πŸ’‘ Approach (Prefix Sum) 1️⃣ Count words starting & ending with vowels, storing cumulative counts 2️⃣ For each query, use pf_sum[r] - pf_sum[l-1] formula 3️⃣ Store results for all queries

πŸš€ #LeetCode POTD (Day 59) βœ…

Count Vowel Strings in Ranges

πŸ’‘ Approach (Prefix Sum)

1️⃣ Count words starting & ending with vowels, storing cumulative counts
2️⃣ For each query, use pf_sum[r] - pf_sum[l-1] formula
3️⃣ Store results for all queries
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 61) βœ… πŸ’‘ Approach (Set + Two Pointers) 1️⃣ Identify first & last occurrence of each character. 2️⃣ Collect unique middle characters for valid ranges. 3️⃣ Return the count of unique palindromic subsequences.

πŸš€ #LeetCode POTD (Day 61) βœ…

πŸ’‘ Approach (Set + Two Pointers)

1️⃣ Identify first & last occurrence of each character.
2️⃣ Collect unique middle characters for valid ranges.
3️⃣ Return the count of unique palindromic subsequences.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 62) βœ… Shifting Letters II πŸ’‘ Approach (Difference Array Pattern) 1️⃣ Build difference array for range shifts. 2️⃣ Compute cumulative shifts with prefix sum. 3️⃣ Apply mod 26 to handle shifts (negative/large), wrapping 'a' to 'z' accordingly.

πŸš€ #LeetCode POTD (Day 62) βœ…

 Shifting Letters II

πŸ’‘ Approach (Difference Array Pattern)

1️⃣ Build difference array for range shifts.
2️⃣ Compute cumulative shifts with prefix sum.
3️⃣ Apply mod 26 to handle shifts (negative/large), wrapping 'a' to 'z' accordingly.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 65) βœ… πŸ’‘ Approach (Brute Force) 1️⃣ For each word pair (i, j) where i < j, check if the first word is both a prefix and suffix of the second. 2️⃣ Use find and rfind to verify prefix-suffix match. 3️⃣ Count and return total valid pairs.

πŸš€ #LeetCode POTD (Day 65) βœ…

πŸ’‘ Approach (Brute Force)

1️⃣ For each word pair (i, j) where i &lt; j, check if the first word is both a prefix and suffix of the second.

2️⃣ Use find and rfind to verify prefix-suffix match.

3️⃣ Count and return total valid pairs.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 66) βœ… Counting Words With a Given Prefix πŸ’‘ Approach (String Matching) 1️⃣ Loop through the words, check if each starts with the prefix using starts_with(). 2️⃣ Increment a counter for each match and return the total.

πŸš€ #LeetCode POTD (Day 66) βœ…

Counting Words With a Given Prefix

πŸ’‘ Approach (String Matching)

1️⃣ Loop through the words, check if each starts with the prefix using starts_with().

2️⃣ Increment a counter for each match and return the total.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 72) βœ… πŸ’‘ Approach (Bit Manipulation) 1️⃣ Count set bits in num1 & num2 using __builtin_popcount(). 2️⃣ If num1 has fewer set bits, turn on unset bits from LSB. 3️⃣ If num1 has more set bits, turn off set bits from LSB.

πŸš€ #LeetCode POTD (Day 72) βœ…

πŸ’‘ Approach (Bit Manipulation)

1️⃣ Count set bits in num1 &amp; num2 using __builtin_popcount().

2️⃣ If num1 has fewer set bits, turn on unset bits from LSB.

3️⃣ If num1 has more set bits, turn off set bits from LSB.
DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 73) βœ… πŸ’‘ Approach (Bit Manipulation) 1️⃣ Elements with even frequency cancel out: x ^ x = 0 2️⃣ If nums1.size() is odd, XOR all elements of nums2. 3️⃣ If nums2.size() is odd, XOR all elements of nums1. 4️⃣ Return the final XOR result.

πŸš€ #LeetCode POTD (Day 73) βœ…

πŸ’‘ Approach (Bit Manipulation)

1️⃣ Elements with even frequency cancel out: x ^ x = 0
2️⃣ If nums1.size() is odd, XOR all elements of nums2.
3️⃣ If nums2.size() is odd, XOR all elements of nums1.
4️⃣ Return the final XOR result.
Arindam Majumder 𝕏 (@arindam_1729) 's Twitter Profile Photo

You don't need to know everything to be a developer. You need just enough knowledge to ask the right questions and make meaningful progress.

DevVortex (@dev_vortex_) 's Twitter Profile Photo

πŸš€ #LeetCode POTD (Day 74) βœ… πŸ’‘ Approach (Bit Manipulation) : 1️⃣ In a circular XOR, original[0] repeats twice, so XOR of all derived must be 0. 2️⃣ Compute XOR of all derived elements. 3️⃣ Return true if XOR == 0, else false.

πŸš€ #LeetCode POTD (Day 74) βœ…

πŸ’‘ Approach (Bit Manipulation) :

1️⃣ In a circular XOR, original[0] repeats twice, so XOR of all derived must be 0.
2️⃣ Compute XOR of all derived elements.
3️⃣ Return true if XOR == 0, else false.