Top Tweets for #LeetCodeChallenge
Day 111 of my #LeetCodeChallenge 🔥
Today’s problem:
1390. Four Divisors
At first glance, it feels like a simple divisor-counting problem 🧮
But brute force is the trap here.
You’re given an array of numbers.
For each number, sum its divisors only if it has exactly 4.
The real trick 👇
👉 Stop early. Don’t overcount.
Key observation:
• Divisors always come in pairs
• If i divides n, then n / i also divides n
• You only need to check up to √n
• If divisors exceed 4 → discard immediately
Why this matters:
• Avoids unnecessary computation
• Keeps the solution efficient even for large numbers
• Clean logic beats complex math
How it works:
• Start with [1, n]
• Iterate from 2 → √n
• Add divisor pairs
• Break as soon as count > 4
• Sum only when count === 4
Complexity:
O(n × √m) time
O(1) space
Takeaway:
Early pruning goes a long way.
Understanding divisor behavior saves work.
Simple loops + smart breaks = efficient solutions.
Full write-up + JavaScript solution 👇
https://t.co/Mv03r3Z57a
#100DaysOfCode #LeetCode #Day111 #NumberTheory #Math #Optimization #JavaScript #Medium #CodingJourney
![nitinahirwal_in's tweet photo. Day 111 of my #LeetCodeChallenge 🔥
Today’s problem:
1390. Four Divisors
At first glance, it feels like a simple divisor-counting problem 🧮
But brute force is the trap here.
You’re given an array of numbers.
For each number, sum its divisors only if it has exactly 4.
The real trick 👇
👉 Stop early. Don’t overcount.
Key observation:
• Divisors always come in pairs
• If i divides n, then n / i also divides n
• You only need to check up to √n
• If divisors exceed 4 → discard immediately
Why this matters:
• Avoids unnecessary computation
• Keeps the solution efficient even for large numbers
• Clean logic beats complex math
How it works:
• Start with [1, n]
• Iterate from 2 → √n
• Add divisor pairs
• Break as soon as count > 4
• Sum only when count === 4
Complexity:
O(n × √m) time
O(1) space
Takeaway:
Early pruning goes a long way.
Understanding divisor behavior saves work.
Simple loops + smart breaks = efficient solutions.
Full write-up + JavaScript solution 👇
https://t.co/Mv03r3Z57a
#100DaysOfCode #LeetCode #Day111 #NumberTheory #Math #Optimization #JavaScript #Medium #CodingJourney](https://pbs.twimg.com/media/G91bPs4bcAABfRO.jpg)
Day 110 of my #LeetCodeChallenge 🔥
Today’s problem:
1411. Number of Ways to Paint N × 3 Grid
At first glance, it feels like a scary grid-coloring problem 🎨
But brute force isn’t the answer here.
You’re given an n × 3 grid and 3 colors.
No two adjacent cells can have the same color.
The real trick 👇
👉 Observe the pattern, not the colors.
Key observation:
• Every row fits into only 2 patterns
• ABA → first & third same, middle different
• ABC → all three different
• Each has 6 valid colorings
Why this matters:
• A row depends only on the previous row’s pattern
• Exact colors don’t matter — only the pattern does
• Track just 2 states, not all combinations
How it works:
• same → ABA patterns
• diff → ABC patterns
• Update counts row by row using DP + state compression
• Apply modulo at each step
Complexity:
O(n) time
O(1) space
Takeaway:
Pattern recognition simplifies complex grids.
State compression turns exponential problems into linear ones.
Clean thinking > brute force.
Full write-up + JavaScript solution 👇
https://t.co/t9hrNxUC8e
#100DaysOfCode #LeetCode #Day110 #DynamicProgramming #StateCompression #JavaScript #Hard #CodingJourney

Day 109 of my #LeetCodeChallenge 🔥
Today’s problem:
961. N-Repeated Element in Size 2N Array
Sounds like a counting problem at first 🤔
But brute force isn’t the point here.
You’re given a 2n sized array where one element appears n times.
The real trick 👇
👉 That element is everywhere.
Key observation:
• The repeated element can’t stay far apart
• In any small window, it must appear at least twice
• So no hash map needed — just compare nearby elements
How it works:
• Traverse the array left to right
• Compare nums[i] with i+1, i+2, i+3
• The first match you find is the answer
That’s it.
Simple logic > extra space.
Complexity:
O(n) time
O(1) space
Takeaway:
Constraints often hide the real solution.
Observation can beat brute force — and even beat hash maps.
Full write-up + JavaScript solution 👇
https://t.co/iCtYPT1WXZ
#100DaysOfCode #LeetCode #Day109 #Arrays #Observation #JavaScript #CodingJourney
![nitinahirwal_in's tweet photo. Day 109 of my #LeetCodeChallenge 🔥
Today’s problem:
961. N-Repeated Element in Size 2N Array
Sounds like a counting problem at first 🤔
But brute force isn’t the point here.
You’re given a 2n sized array where one element appears n times.
The real trick 👇
👉 That element is everywhere.
Key observation:
• The repeated element can’t stay far apart
• In any small window, it must appear at least twice
• So no hash map needed — just compare nearby elements
How it works:
• Traverse the array left to right
• Compare nums[i] with i+1, i+2, i+3
• The first match you find is the answer
That’s it.
Simple logic > extra space.
Complexity:
O(n) time
O(1) space
Takeaway:
Constraints often hide the real solution.
Observation can beat brute force — and even beat hash maps.
Full write-up + JavaScript solution 👇
https://t.co/iCtYPT1WXZ
#100DaysOfCode #LeetCode #Day109 #Arrays #Observation #JavaScript #CodingJourney](https://pbs.twimg.com/media/G9q6UhdbcAAqklg.jpg)
Day 108 of my #LeetCodeChallenge 🔥
Today’s problem:
66. Plus One
Looks trivial at first glance 😄
But this one quietly tests how cleanly you handle edge cases.
You’re given a number as an array of digits and asked to add one.
No big integers. No shortcuts.
The key realization 👇
👉 This is just elementary addition with carry, applied to an array.
How it plays out:
• Start from the last digit
• If it’s < 9 → increment and done
• If it’s 9 → turn it into 0 and carry left
• If all digits are 9 → add a new leading 1
That’s it. Simple, precise, and efficient.
Complexity:
O(n) time
O(1) space
Takeaway:
Easy problems don’t test intelligence — they test discipline.
Clean carry handling shows up again and again in harder problems.
Full write-up + JavaScript solution 👇
https://t.co/Ciw5WfVXAV
#100DaysOfCode #LeetCode #Day108 #Arrays #Math #JavaScript #CodingJourney

Day 107 of my #LeetCodeChallenge 🔥
Today’s problem:
1970. Last Day Where You Can Still Cross
At first glance, this grid problem feels messy 😅
Cells flood day by day, paths disappear, and brute force just won’t work.
The key realization for me was this 👇
👉 The problem has monotonic behavior
• If you can cross on day d, you can cross on all days < d
• If you can’t cross on day d, you’ll never cross on days > d
That single insight changes everything.
From there, the solution becomes clear:
• Binary search on the day
• For each day, check reachability using BFS
• Start from the top row, try to reach the bottom
• Push the search as far right as possible
Complexity:
O((row × col) log(row × col)) time
O(row × col) space
Takeaway:
Hard problems often hide behind simple patterns.
Once you spot monotonic feasibility, binary search becomes your best friend.
Full write-up + JavaScript solution 👇
https://t.co/yphB7J0uMo
#100DaysOfCode #LeetCode #Day107 #BinarySearch #BFS #Graphs #JavaScript #CodingJourney

Day 93 of my #LeetCodeChallenge 🔥
Today’s problem:
3573. Best Time to Buy and Sell Stock V
At first glance, allowing short selling makes this problem feel intimidating 😅
But once you step back, the complexity melts away.
You’re given stock prices and up to k transactions.
Each transaction can be:
• Normal → buy then sell
• Short → sell then buy back
The key realization for me was this:
👉 Every transaction is just opening a position and closing it later — direction doesn’t matter.
So at any moment, you can only be in one of three states:
• No position
• Holding a long position
• Holding a short position
Once a position is closed, that’s one full transaction done.
From there, the solution naturally becomes a state-based DP:
• Track transactions used
• Track current position state
• Move day by day
• Optimize space by keeping only the current DP row
Complexity:
O(n × k) time
O(k) space
Takeaway:
When problems add “new rules”, don’t panic —
most of the time it’s just one more state in a familiar pattern.
Clean state modeling turns chaos into clarity.
Full write-up + JavaScript solution 👇
https://t.co/727Slph5Me
#100DaysOfCode #LeetCode #Day93 #DynamicProgramming #Stocks #JavaScript #CodingJourney

Day 91 of my #LeetCodeChallenge 🔥
Today’s problem:
2110. Number of Smooth Descent Periods of a Stock
At first glance, it feels like a brute-force subarray problem… but it turns out to be all about spotting a simple pattern 😄
You’re given daily stock prices.
A smooth descent period:
• Is contiguous
• Drops by exactly 1 each day
• A single day always counts
The key insight for me was this:
👉 You don’t need to check all subarrays.
Instead, track what ends at the current index.
If prices keep decreasing by 1:
• Extend the current descent streak
• A streak of length k contributes k valid periods ending there
So the solution becomes:
• Traverse once
• Track current descent length
• Reset when the pattern breaks
• Add the streak length to the answer each step
Complexity:
O(n) time
O(1) space
Takeaway:
Many array problems become trivial once you stop thinking in subarrays and start thinking in patterns ending at each index.
One-pass solutions are often hiding in plain sight.
Full write-up + JavaScript solution:
https://t.co/3isP0uD9G7
#100DaysOfCode #LeetCode #Day91 #JavaScript #Arrays #Counting #CodingJourney

Day 90 of my #LeetCodeChallenge 🔥
Today’s problem:
2147. Number of Ways to Divide a Long Corridor
This one looks like a simple string problem… until you realize it’s all about counting the right choices 😄
You’re given a corridor with:
• Seats (S)
• Plants (P)
Rules are strict:
• Each section must have exactly two seats
• Plants can be anywhere
• Dividers can only go between positions
The big insight for me was this:
👉 Once seats are grouped into pairs, the only freedom left is where you place dividers between consecutive seat-pairs.
And that freedom comes from plants.
If there are k plants between two seat-pairs, you get:
k + 1 possible divider positions.
So the solution becomes:
• Traverse once
• Count seats
• For every completed pair, count plants until the next seat
• Multiply (plants + 1)
• If seats are odd or zero → answer is 0
Complexity:
O(n) time
O(1) space
Takeaway:
Hard problems often hide very simple math underneath.
Once you lock onto the core constraint (exactly two seats), everything else falls into place beautifully.
Full write-up + JavaScript solution:
https://t.co/aqxMkDFOvi
#100DaysOfCode #LeetCode #Day90 #JavaScript #Greedy #Combinatorics #CodingJourney

Day 88 of my #LeetCodeChallenge 🔥
Today’s problem:
3433. Count Mentions Per User
This one surprised me. It looks simple at first… until you realize how much the order of events changes everything 😅
The setup feels like building a mini chat app:
• Users can go offline for 60 time units
• Messages can tag ALL users
• Or only online users (HERE)
• Or specific users (idX)
And the kicker:
If OFFLINE and MESSAGE share the same timestamp, the user goes offline before the message is processed.
One small rule that completely shifts the results.
My approach was to simulate the timeline:
Sort events by timestamp
Always handle OFFLINE before MESSAGE
Track when each user becomes online again
Parse every message token and update mention counts
Once that part fell into place, the problem became surprisingly clean.
Complexity:
O(n * users) time
O(users) space
Takeaway:
Even simple simulations depend heavily on processing order. One tiny rule can flip the entire logic — which is why I enjoyed this one more than expected.
Full write-up + JavaScript solution:
https://t.co/9Rw3ZX3Rbn
#100DaysOfCode #LeetCode #Day88 #JavaScript #Simulation #CodingJourney 🚀

Day 87 of my #LeetCodeChallenge
Today’s problem:
3531. Count Covered Buildings
Core Idea
A building is covered only if it has:
one building on the left
one on the right
one above
one below
Instead of scanning the grid, we just track boundaries in each row and column.
Key Insight
For a building at (x, y) to be covered:
rowMin[x] < y < rowMax[x]
colMin[y] < x < colMax[y]
If both conditions hold, the building is covered.
Approach
Build four maps: rowMin, rowMax, colMin, colMax
Fill them in one pass
In another pass, check if each building lies strictly between the min and max of its row and column
Count those that satisfy all four directions
Complexity
O(m) time
O(m) space
Takeaway
2D grid problems often become simple boundary checks with min/max preprocessing.
Full write-up + JavaScript solution:
https://t.co/WxHGQ9EZdd
#100DaysOfCode #LeetCode #Day87 #JavaScript #Geometry #HashMap #DSA #Algorithms
![nitinahirwal_in's tweet photo. Day 87 of my #LeetCodeChallenge
Today’s problem:
3531. Count Covered Buildings
Core Idea
A building is covered only if it has:
one building on the left
one on the right
one above
one below
Instead of scanning the grid, we just track boundaries in each row and column.
Key Insight
For a building at (x, y) to be covered:
rowMin[x] < y < rowMax[x]
colMin[y] < x < colMax[y]
If both conditions hold, the building is covered.
Approach
Build four maps: rowMin, rowMax, colMin, colMax
Fill them in one pass
In another pass, check if each building lies strictly between the min and max of its row and column
Count those that satisfy all four directions
Complexity
O(m) time
O(m) space
Takeaway
2D grid problems often become simple boundary checks with min/max preprocessing.
Full write-up + JavaScript solution:
https://t.co/WxHGQ9EZdd
#100DaysOfCode #LeetCode #Day87 #JavaScript #Geometry #HashMap #DSA #Algorithms](https://pbs.twimg.com/media/G75m-RnaMAAzOZm.jpg)
Day 86 of my #LeetCodeChallenge 🔥
Today’s problem:
3577. Count the Number of Computer Unlocking Permutations
Core Idea
Everything depends on the root computer ✅
If computer 0 can unlock everyone, the rest becomes trivial.
Key Observation
To unlock any computer i (>0), we must already have:
• some j < i
• complexity[j] < complexity[i]
If complexity[0] is NOT the strict minimum → impossible
If complexity[0] IS the unique global minimum → valid ✅
Then:
• 0 must be first
• remaining computers can be in ANY order
Total permutations = (n − 1)!
Approach
• Check if complexity[0] is strictly smaller than all others
• If not, return 0
• Else compute (n − 1)! mod 1e9+7 (BigInt in JS)
Complexity
O(n) time
O(1) space
Takeaway
One constraint can turn a permutation problem into a simple factorial.
Full write-up + JavaScript solution:
https://t.co/9G8cuc2yxA
#100DaysOfCode #LeetCode #Day86 #JavaScript #Math #Permutations #Greedy #DSA #Algorithms
![nitinahirwal_in's tweet photo. Day 86 of my #LeetCodeChallenge 🔥
Today’s problem:
3577. Count the Number of Computer Unlocking Permutations
Core Idea
Everything depends on the root computer ✅
If computer 0 can unlock everyone, the rest becomes trivial.
Key Observation
To unlock any computer i (>0), we must already have:
• some j < i
• complexity[j] < complexity[i]
If complexity[0] is NOT the strict minimum → impossible
If complexity[0] IS the unique global minimum → valid ✅
Then:
• 0 must be first
• remaining computers can be in ANY order
Total permutations = (n − 1)!
Approach
• Check if complexity[0] is strictly smaller than all others
• If not, return 0
• Else compute (n − 1)! mod 1e9+7 (BigInt in JS)
Complexity
O(n) time
O(1) space
Takeaway
One constraint can turn a permutation problem into a simple factorial.
Full write-up + JavaScript solution:
https://t.co/9G8cuc2yxA
#100DaysOfCode #LeetCode #Day86 #JavaScript #Math #Permutations #Greedy #DSA #Algorithms](https://pbs.twimg.com/media/G70kwzCagAAJ_2u.jpg)
Day 85 of my #LeetCodeChallenge 🔥
Today’s problem:
3583. Count Special Triplets
Core Idea
Every valid triplet is driven by the middle element ✅
If we fix index j, the problem simplifies beautifully.
Key Observation
We’re looking for triplets where:
nums[i] = nums[j] * 2
nums[k] = nums[j] * 2
with i < j < k
Instead of brute force:
• Fix the middle index j
• Count how many nums[j] * 2 exist before j
• Count how many nums[j] * 2 exist after j
• Multiply both counts → valid triplets ✅
Approach
• Maintain two frequency arrays: left and right
• Initialize right with all counts
• Traverse the array using each index as j
• Update right, compute target, add left[target] * right[target]
• Update left for the next iteration
Complexity
O(n) time
O(U) space, where U = 10^5
Takeaway
Fixing one index can turn a 3-loop problem into a linear one.
Frequency counting + prefix/suffix thinking beats brute force.
Full write-up + JavaScript solution:
https://t.co/SJSpjfHQYT
#100DaysOfCode #LeetCode #Day85 #JavaScript #Arrays #DSA #Algorithms #CodingChallenge 🚀
![nitinahirwal_in's tweet photo. Day 85 of my #LeetCodeChallenge 🔥
Today’s problem:
3583. Count Special Triplets
Core Idea
Every valid triplet is driven by the middle element ✅
If we fix index j, the problem simplifies beautifully.
Key Observation
We’re looking for triplets where:
nums[i] = nums[j] * 2
nums[k] = nums[j] * 2
with i < j < k
Instead of brute force:
• Fix the middle index j
• Count how many nums[j] * 2 exist before j
• Count how many nums[j] * 2 exist after j
• Multiply both counts → valid triplets ✅
Approach
• Maintain two frequency arrays: left and right
• Initialize right with all counts
• Traverse the array using each index as j
• Update right, compute target, add left[target] * right[target]
• Update left for the next iteration
Complexity
O(n) time
O(U) space, where U = 10^5
Takeaway
Fixing one index can turn a 3-loop problem into a linear one.
Frequency counting + prefix/suffix thinking beats brute force.
Full write-up + JavaScript solution:
https://t.co/SJSpjfHQYT
#100DaysOfCode #LeetCode #Day85 #JavaScript #Arrays #DSA #Algorithms #CodingChallenge 🚀](https://pbs.twimg.com/media/G7vZ5Rxb0AAgPvr.jpg)
Day 84 of my #LeetCodeChallenge 🔥
Today’s problem:
1925. Count Square Sum Triples
Core Idea
The equation points straight to the classic Pythagorean theorem ✅
Since constraints are small, brute force isn’t scary — if done right.
Key Observation
We’re looking for ordered triples where:
a² + b² = c²
Instead of searching for c every time:
• Precompute all squares from 1² to n²
• Store them in a Set for O(1) lookup
• Check if a² + b² exists in that set
Fast ✅ Clean ✅ Reliable ✅
Approach
• Precompute squares up to n
• Loop over all ordered pairs (a, b)
• Check if a² + b² is a valid square
• Count both (a, b, c) and (b, a, c)
Complexity
O(n²) time
O(n) space
Given n ≤ 250, this is perfectly acceptable.
Takeaway
Constraints define the solution.
Precomputation can turn brute force into a clean and efficient approach.
Full write-up + JavaScript solution:
https://t.co/OKhugDd608
#100DaysOfCode #LeetCode #Day84 #JavaScript #Math #BruteForce #DSA #Algorithms #CodingChallenge

Day 83 of my #LeetCodeChallenge 🔥
Today’s problem:
1523. Count Odd Numbers in an Interval Range
Core Idea
Looping through the range is unnecessary ❌
Odd numbers follow a fixed pattern — every alternate number is odd.
The key observation:
The number of odd integers from 0 to x (inclusive) is:
floor((x + 1) / 2)
So the count of odd numbers in [low, high] is just:
odds(0..high) − odds(0..low−1)
Pure math. No iteration needed.
Approach
• Count odd numbers from 0 to high
• Count odd numbers from 0 to low − 1
• Subtract the two values
• Done in constant time
A simple formula replaces the entire loop.
Complexity
O(1) time — single calculation
O(1) space — no extra memory
Takeaway
Not every problem needs loops.
Pattern recognition + math can beat brute force every time.
Full write-up + JavaScript solution:
https://t.co/Z26JL8BVkX
#100DaysOfCode #LeetCode #JavaScript #Math #Parity #DSA #CodingChallenge #Algorithms 🚀
![nitinahirwal_in's tweet photo. Day 83 of my #LeetCodeChallenge 🔥
Today’s problem:
1523. Count Odd Numbers in an Interval Range
Core Idea
Looping through the range is unnecessary ❌
Odd numbers follow a fixed pattern — every alternate number is odd.
The key observation:
The number of odd integers from 0 to x (inclusive) is:
floor((x + 1) / 2)
So the count of odd numbers in [low, high] is just:
odds(0..high) − odds(0..low−1)
Pure math. No iteration needed.
Approach
• Count odd numbers from 0 to high
• Count odd numbers from 0 to low − 1
• Subtract the two values
• Done in constant time
A simple formula replaces the entire loop.
Complexity
O(1) time — single calculation
O(1) space — no extra memory
Takeaway
Not every problem needs loops.
Pattern recognition + math can beat brute force every time.
Full write-up + JavaScript solution:
https://t.co/Z26JL8BVkX
#100DaysOfCode #LeetCode #JavaScript #Math #Parity #DSA #CodingChallenge #Algorithms 🚀](https://pbs.twimg.com/media/G7lXfW4bMAAvyrP.jpg)
Day 82 of my #LeetCodeChallenge 🔥
Today’s problem:
3578. Count Partitions With Max-Min Difference at Most K
Core Idea
Brute-forcing all partitions is exponential ❌
The key observation:
For any right index i, once we find the earliest L such that
max(nums[L..i]) - min(nums[L..i]) ≤ k
Every subarray [l..i] with l ≥ L is automatically valid.
So counting partitions becomes a window + DP problem.
Approach
• Sliding Window to maintain validity
• Monotonic Deques to track max & min in O(1)
• Dynamic Programming where
dp[i] = number of ways to partition prefix [0..i-1]
• Prefix sums to compute transitions in constant time
No nested loops. Fully linear.
Complexity
O(n) time — each element enters & leaves the window once
O(n) space — DP, prefix sums, and deques
Takeaway
Sliding window prunes the search space.
Monotonic queues make range max/min efficient.
Prefix sums turn DP from quadratic to linear.
This combination shows up again and again in medium–hard problems.
Full write-up + JavaScript solution:
https://t.co/mbbifYqn4U
#100DaysOfCode #LeetCode #JavaScript #SlidingWindow #DynamicProgramming #MonotonicQueue #DSA #Algorithms 🚀
![nitinahirwal_in's tweet photo. Day 82 of my #LeetCodeChallenge 🔥
Today’s problem:
3578. Count Partitions With Max-Min Difference at Most K
Core Idea
Brute-forcing all partitions is exponential ❌
The key observation:
For any right index i, once we find the earliest L such that
max(nums[L..i]) - min(nums[L..i]) ≤ k
Every subarray [l..i] with l ≥ L is automatically valid.
So counting partitions becomes a window + DP problem.
Approach
• Sliding Window to maintain validity
• Monotonic Deques to track max & min in O(1)
• Dynamic Programming where
dp[i] = number of ways to partition prefix [0..i-1]
• Prefix sums to compute transitions in constant time
No nested loops. Fully linear.
Complexity
O(n) time — each element enters & leaves the window once
O(n) space — DP, prefix sums, and deques
Takeaway
Sliding window prunes the search space.
Monotonic queues make range max/min efficient.
Prefix sums turn DP from quadratic to linear.
This combination shows up again and again in medium–hard problems.
Full write-up + JavaScript solution:
https://t.co/mbbifYqn4U
#100DaysOfCode #LeetCode #JavaScript #SlidingWindow #DynamicProgramming #MonotonicQueue #DSA #Algorithms 🚀](https://pbs.twimg.com/media/G7f4xIxa0AI0DCX.jpg)
Day 81 of my #LeetCodeChallenge 🔥
Today’s problem:
3432. Count Partitions with Even Sum Difference
🧠 Core Idea
The key insight is mathematical:
A partition is valid if
sum(left) - sum(right) is even.
Rewrite it as:
diff = 2L - S
Since 2L is always even, the parity depends only on total sum S.
So:
✔ If S is even → all (n−1) partitions are valid
✖ If S is odd → zero partitions are valid
A single parity check replaces the entire problem.
🧩 Approach
• Compute total sum S
• If S is even → return n − 1
• If S is odd → return 0
No prefix sums. No checking each index. Pure math.
⚡ Complexity
O(n) time — one pass
O(1) space — constant memory
✨ Takeaway
Sometimes the simplest problems hide the cleanest math tricks.
Parity > brute force.
👉 Full write-up + JS solution —
https://t.co/J2AdyjX6BT
#100DaysOfCode #LeetCode #JavaScript #Math #DSA #CodingChallenge #ProblemSolving #Algorithms

Day 80 of my #LeetCodeChallenge 🔥
Today’s problem:
2211. Count Collisions on a Road
🧠 Core Idea
Cars at the boundaries that move outward (L on the left, R on the right) will never collide — they escape the system.
Once we trim these cars, every remaining L or R in the middle is guaranteed to collide.
So instead of simulating movement, we simply:
Skip leading Ls
Skip trailing Rs
Count all remaining moving cars (L or R) → each contributes 1 collision
A smart observation replaces an entire simulation.
🧩 Approach
• Use two pointers to trim escape cars
• The substring between them is the collision zone
• Count non-S cars (all moving cars)
• That count = total collisions
⚡ Complexity
O(n) time — single scan
O(1) space — constant pointers
✨ Takeaway
Pattern recognition > brute force.
Understanding which cars must collide and which cannot collide makes this a beautifully simple problem.
👉 Full write-up + JS solution —
https://t.co/L9Y0w1uKdd
#100DaysOfCode #LeetCode #JavaScript #Greedy #Simulation #DSA #CodingChallenge #ProblemSolving #Algorithms

Day 72 of my #LeetCodeChallenge 🔥
Today’s problem:
2435. Paths in Matrix Whose Sum Is Divisible by K
🧠 Core Idea
We're counting paths in an m x n grid where the sum of the path is divisible by k.
Instead of tracking large sums, we only track the remainder modulo k at every cell — that’s the key insight.
Each cell can be reached from top or left, and for every path we maintain how many ways we can arrive with every possible remainder 0…k-1.
🧩 Approach
• Define a DP state: dp[j][r] → ways to reach column j with remainder r
• Use rolling DP to keep space small (only the current row)
• For each cell:
– Take value val % k
– Combine paths from top & left
– Update new remainders: (r + val) % k
• Base case: start at (0,0) with remainder grid[0][0] % k
• Final answer: dp[lastColumn][0] → paths whose sum is divisible by k
⚡ Complexity
O(m × n × k) time
O(n × k) space (rolled DP)
✨ Takeaway
When sums get too large, remainders save the day.
Modulo-based DP turns a heavy problem into a clean, elegant solution — especially with smart space optimization 🚀
👉 Full write-up + JS solution —
https://t.co/0Q0BsAbKEI
#100DaysOfCode #LeetCode #JavaScript #DynamicProgramming #GridDP #ModularArithmetic #DSA #ProblemSolving #CodingChallenge #Algorithms
![nitinahirwal_in's tweet photo. Day 72 of my #LeetCodeChallenge 🔥
Today’s problem:
2435. Paths in Matrix Whose Sum Is Divisible by K
🧠 Core Idea
We're counting paths in an m x n grid where the sum of the path is divisible by k.
Instead of tracking large sums, we only track the remainder modulo k at every cell — that’s the key insight.
Each cell can be reached from top or left, and for every path we maintain how many ways we can arrive with every possible remainder 0…k-1.
🧩 Approach
• Define a DP state: dp[j][r] → ways to reach column j with remainder r
• Use rolling DP to keep space small (only the current row)
• For each cell:
– Take value val % k
– Combine paths from top & left
– Update new remainders: (r + val) % k
• Base case: start at (0,0) with remainder grid[0][0] % k
• Final answer: dp[lastColumn][0] → paths whose sum is divisible by k
⚡ Complexity
O(m × n × k) time
O(n × k) space (rolled DP)
✨ Takeaway
When sums get too large, remainders save the day.
Modulo-based DP turns a heavy problem into a clean, elegant solution — especially with smart space optimization 🚀
👉 Full write-up + JS solution —
https://t.co/0Q0BsAbKEI
#100DaysOfCode #LeetCode #JavaScript #DynamicProgramming #GridDP #ModularArithmetic #DSA #ProblemSolving #CodingChallenge #Algorithms](https://pbs.twimg.com/media/G6sQjXgbEAAYyTK.jpg)
Day 71 of my #LeetCodeChallenge 🔥
Today’s problem:
1015. Smallest Integer Divisible by K
🧠 Core Idea
We’re looking for the smallest number made only of digit ‘1’ (a repunit) that’s divisible by k.
Since these numbers grow huge, we never build them directly — instead, we track only their remainder modulo k.
Two key insights:
• If k is divisible by 2 or 5, no repunit can ever divide it → return -1
• Using the pigeonhole principle, checking up to k remainders is guaranteed to find the answer or prove it's impossible
🧩 Approach
• If k % 2 == 0 or k % 5 == 0: return -1
• Maintain rem = 0
• For each length from 1 to k:
rem = (rem * 10 + 1) % k
• If rem === 0, that length is the answer
• At most k iterations needed — clean & guaranteed
⚡ Complexity
O(k) time — up to k remainder checks
O(1) space — only storing a single remainder
✨ Takeaway
You don’t need to construct gigantic numbers —
just track their behavior modulo k.
Modular arithmetic + number theory = elegant and efficient solution 🚀
👉 Full write-up + JS solution —
https://t.co/fkGp6TIcxr
#100DaysOfCode #LeetCode #JavaScript #Math #NumberTheory #ModularArithmetic #DSA #ProblemSolving #CodingChallenge #Algorithms

Day 69 of my #LeetCodeChallenge 🔥
Today’s problem:
1262. Greatest Sum Divisible by Three
🧩 Approach
• Start with the sum of all numbers — the maximum possible result
• If the sum is already divisible by 3 → return it
• Otherwise, remove the smallest value that fixes divisibility
• Track the two smallest (num % 3 == 1) and two smallest (num % 3 == 2)
• Remove either 1 element or 2 elements — whichever causes minimum loss to the total
⚡ Complexity
O(n) time — single scan
O(1) space — constant memory
✨ Takeaway
Optimization isn’t always about adding more —
sometimes the smartest move is removing the smallest cost to unlock the maximum result.
Greedy + modular arithmetic beats DP here 🚀
👉 Full write-up + JS solution —
https://t.co/FZWtmoYQw5
#100DaysOfCode #LeetCode #JavaScript #Greedy #Math #DSA #ProblemSolving #CodingChallenge #Algorithms

Day 68 of my #LeetCodeChallenge 🔥
Today’s problem:
3190. Find Minimum Operations to Make All Elements Divisible by Three
🧩 Approach
• Each number is at most 1 step away from being divisible by 3
• If num % 3 === 0 → 0 ops
• If num % 3 === 1 → subtract 1 (1 op)
• If num % 3 === 2 → add 1 (1 op)
• So answer = count of elements not divisible by 3
⚡ Complexity
O(n) time
O(1) space
✨ Takeaway
Sometimes the fastest solution comes from spotting a math pattern, not simulation.
Every number being only one step from a multiple of 3 leads to an elegant linear solution.
👉 Full write-up + JS solution —
https://t.co/1FEEEPw4lT
#100DaysOfCode #LeetCode #JavaScript #Math #Greedy #DSA #ProblemSolving #CodingChallenge #Algorithms 🚀

Day 66 of my #LeetCodeChallenge 🔥
Today’s problem:
757. Set Intersection Size At Least Two
🧩 Approach
• Sort intervals by end ascending (and start descending on ties)
• Track the two most recent selected points: last1 < last2
• For each interval:
– If 0 points inside → add b-1 and b
– If 1 point inside → add b
– If 2 points inside → do nothing
• Greedy placement at the rightmost side gives minimal total picks
⚡ Complexity
O(n log n) time (sorting)
O(1) space
✨ Takeaway
Smart greedy + interval sorting minimizes overlap cost.
Placing points at the interval end maximizes reuse across future intervals.
👉 Full write-up + JS solution —
https://t.co/HJX4yTVVxk
#100DaysOfCode #LeetCode #JavaScript #Greedy #Intervals #Algorithms #ProblemSolving #CodingChallenge #DSA

Day 64 of my #LeetCodeChallenge 🔥
Today’s problem:
717. 1-bit and 2-bit Characters
🧩 Approach
• Decode left-to-right
• If you see 1 → skip the next bit (two-bit char)
• If you see 0 → move one step (one-bit char)
• After processing, check if the pointer lands exactly on the last index
• If yes → last 0 is a standalone one-bit char
• Clean simulation — no extra structures needed
⚡ Complexity
O(n) time
O(1) space
✨ Takeaway
Simulation wins again!
Track only what matters — the current index — and follow the encoding rules. Simple, predictable, effective. 💡
👉 Full write-up + JS solution —
https://t.co/ZtxPi5Rrgg
#100DaysOfCode #LeetCode #JavaScript #Binary #Simulation #Algorithms #ProblemSolving #CodingChallenge #DSA

Day 63 of my #LeetCodeChallenge 🔥
Today’s problem:
1437. Check If All 1's Are at Least Length K Places Away
🧩 Approach
• Track the index of the previous 1
• For each new 1, check if the gap ≥ k
• If gap < k → return false immediately
• Initialize prev = -k - 1 so the first 1 always passes
• Single left-to-right scan
• Clean distance-check logic → no extra structures
⚡ Complexity
O(n) time
O(1) space
✨ Takeaway
Simple invariants + pointer tracking can solve spacing problems elegantly.
Focus only on what matters — the last seen 1! 💡
👉 Full write-up + JS solution —
https://t.co/bzLEKZKTdc
#100DaysOfCode #LeetCode #JavaScript #Arrays #Algorithms #ProblemSolving #CodingChallenge #DSA

Last Seen Hashtags on Sotwe
Most Popular Users

Elon Musk 
@elonmusk
240M followers

Barack Obama 
@barackobama
118.6M followers

Cristiano Ronaldo 
@cristiano
114.4M followers

Donald J. Trump 
@realdonaldtrump
111.7M followers

Narendra Modi 
@narendramodi
106.9M followers

Rihanna 
@rihanna
98.6M followers

NASA 
@nasa
92.1M followers

Justin Bieber 
@justinbieber
91.7M followers

KATY PERRY 
@katyperry
89.9M followers

Taylor Swift 
@taylorswift13
83.9M followers

Lady Gaga 
@ladygaga
75.4M followers

Virat Kohli 
@imvkohli
73.3M followers

Kim Kardashian 
@kimkardashian
70.8M followers

YouTube 
@youtube
68.6M followers

Neymar Jr 
@neymarjr
66.3M followers

Bill Gates 
@billgates
65.2M followers

Selena Gomez 
@selenagomez
63M followers

The Ellen Show
@theellenshow
62.1M followers

CNN 
@cnn
61.7M followers

X 
@x
60.6M followers
