Day: 36/365 📌 LeetCode POTD: Longest Balanced Subarray II Hard Key takeaways/Learnings from this problem: 1. This one shows how segment trees help maintain balance info over ranges without recomputing everything again and again. 2. Big takeaway: when constraints grow, upgrading from prefix tricks to a range query data structure makes all the difference. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
Longest Balanced Subarray II with Segment Trees
More Relevant Posts
-
Leetcode Problem || Minimum Operations to Equalize Binary String Solved(3666)🚀 Today I worked on an interesting problem involving string transformation operations. Instead of simulating every flip operation directly on the string (which would be expensive), I optimized the approach by: ✔ Converting the problem into tracking only the count of zeros ✔ Modeling the transformation as a graph problem ✔ Using BFS to find minimum operations ✔ Leveraging TreeSet for efficient range pruning ✔ Applying parity-based optimization for faster traversal #Java #DSA #BFS #ProblemSolving #CompetitiveProgramming #CodingJourney
To view or add a comment, sign in
-
-
Day 8 | LeetCode – Delete Node in a Linked List Today, I solved Delete Node in a Linked List — a problem that tests understanding of pointer manipulation rather than traversal. The twist: We are given only the node to delete, not the head of the list. Instead of traditional deletion, the approach was: Copy the value of the next node into the current node Redirect the current node’s next pointer Disconnect the next node This makes the deletion possible in: ✅ Time Complexity: O(1) ✅ Space Complexity: O(1) What I liked about this problem is how it challenges assumptions. Normally, deleting a node requires access to the previous node — but here, the solution comes from modifying the current node itself. A great reminder that understanding data structure behavior deeply is more important than memorizing patterns. #Day8 #DSA #LeetCode #LinkedList #Java #ProblemSolving #Algorithms #InterviewPrep #DailyLearning
To view or add a comment, sign in
-
-
Day 9 of Daily DSA 🚀 Solved LeetCode 11: Container With Most Water ✅ 🔍 Approach: Used the two-pointer technique to efficiently calculate the maximum area. Started with pointers at both ends Calculated area using min height × width Moved the pointer with the smaller height to optimize the result This avoids brute force and ensures an optimal solution. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 5 ms (Beats 80.63%) • Memory: 77.19 MB (Beats 92.56%) A great example of how the right observation can turn a problem into a clean solution. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #DailyCoding
To view or add a comment, sign in
-
-
🔥 Day 82 of my LeetCode Journey 🔥 📘 Problem: 110. Balanced Binary Tree 🎯 Difficulty: Easy 🔹 Problem Statement: Given a binary tree, determine if it is height-balanced. A binary tree is balanced if the height difference between the left and right subtree of every node is not more than 1. 🔹 Approach Used: Traverse the tree using Depth First Search (DFS) Calculate the height of left and right subtrees recursively If the height difference exceeds 1, return -1 to indicate the tree is not balanced Otherwise, return the height of the current node Finally, check if the returned value is -1 or not 🔹 Key Concepts: Binary Tree traversal Depth First Search (DFS) Recursion Height calculation of tree 🔹 Learning: Instead of calculating heights separately for every node (which would increase complexity), this approach combines height calculation and balance checking in a single traversal, making the solution more efficient. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) #LeetCode #Day82 #Java #BinaryTree #DFS #Recursion #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day: 57/365 📌 LeetCode POTD: Special Positions in a Binary Matrix Easy Key takeaways/Learnings from this problem: 1. This one shows how precomputing row and column counts makes checking each cell super easy. 2. Instead of re-scanning the whole row and column every time, count once and reuse smartly. 3. Good reminder that brute force can often be optimized with a tiny bit of preprocessing. 4. Clean implementation and careful condition checking matter more than complex algorithms here. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 Day 84 of #100DaysOfCode Solved LeetCode Problem #3721 – Longest Balanced Subarray II ✅ This one was a solid jump in complexity from Part I. It required a more advanced approach using segment trees with lazy propagation to efficiently handle range updates and queries while tracking balance conditions. Key Takeaways: -> Segment Tree + Lazy Propagation is powerful for range-based balance problems -> Encoding states smartly simplifies transitions -> Performance optimization matters when brute force isn’t an option -> Advanced data structures unlock solutions to “Part II” style problems Language: Java -> Runtime: 349 ms (Beats 73.53%) ⚡ -> Memory: 72.05 MB (Beats 98.53%) One day, one hard problem, steady progress. 💻🔥 #LeetCode #Java #SegmentTree #LazyPropagation #DataStructures #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Solved the classic #linked_list problem https://lnkd.in/gWWFrt_g 👉 Add Two Numbers (LeetCode) Instead of converting the lists into integers, I handled the addition digit-by-digit just like manual addition using: A dummy node to simplify linked list construction ✔️ Carry handling logic ✔️ Clean pointer movement ✔️ O(n) Time Complexity ✔️ O(n) Space Complexity We traverse both linked lists simultaneously, calculate the sum at each node along with the carry, create a new node for the result, and move forward just like elementary school addition. Runtime: 1 ms Faster than 99.79% of Java submissions 1569 / 1569 test cases passed This problem reinforced something important: Strong fundamentals in data structures (especially Linked Lists) make complex-looking problems feel structured and logical. Building logic ! On to the next one ! #Java #LeetCode #DSA #LinkedList
To view or add a comment, sign in
-
-
Solved LeetCode #206 — Reverse Linked List. Problem: Given the head of a singly linked list, reverse the list and return the new head. Example: [1,2,3,4,5] → [5,4,3,2,1] Approach Used: Iterative Pointer Reversal Traverse the list while maintaining three pointers: • prev → stores the previous node • head → current node being processed • next → temporarily stores the next node For each node: Store next = head.next Reverse the pointer → head.next = prev Move pointers forward Continue until the list ends. prev becomes the new head of the reversed list. Complexity • Time Complexity: O(n) • Space Complexity: O(1) A classic linked list problem that strengthens pointer manipulation skills. #LeetCode #DSA #Algorithms #Java #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 64/100 – LeetCode Challenge ✅ Problem: #621 Task Scheduler Difficulty: Medium Language: Java Approach: Greedy with Idle Slot Calculation Time Complexity: O(n) Space Complexity: O(1) Key Insight: Most frequent task determines minimum intervals needed. Arrange tasks in frames: (maxFreq - 1) × (n + 1) + countOfMaxFreq Calculate idle slots needed and add to total tasks. Solution Brief: Count frequencies of each task (A-Z). Find maximum frequency (max) and count how many tasks have it (maxCount). Calculate: partCount = max - 1 partLength = n - (maxCount - 1) emptySlots = partCount × partLength availableTasks = total - max × maxCount idles = max(0, emptySlots - availableTasks) Result = total tasks + idles #LeetCode #Day64 #100DaysOfCode #Greedy #Java #Algorithm #CodingChallenge #ProblemSolving #TaskScheduler #MediumProblem #FrequencyCount #Scheduling #DSA
To view or add a comment, sign in
-
-
Day 11/30 – LeetCode streak Today’s problem: Sort Integers by The Number of 1 Bits You have to sort an array by popcount first (fewer 1s come earlier), and if two numbers have the same count, sort them by their actual value. Instead of using 'Arrays.sort' with a comparator, I tried writing the sort logic myself with insertion sort: - For each element, treat it as 'key' and move larger elements (based on custom “bit count, then value” order) one step to the right. - 'Swap(a, b)' returns true if 'a' should come after 'b' in the final order, using a manual 'countBits' function to compare the number of 1s. - If bit counts differ, the one with more 1s is considered “greater”; if they’re equal, compare the raw integers. Day 11 takeaway: This was a nice chance to practice writing a custom sort order from scratch—once the comparison rule is clear (“by 1-bits, then by value”), the rest is just plugging that into any sorting algorithm. #leetcode #dsa #java #bitmanipulation #sorting
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development