Day 54/100 – #100DaysOfCode 🚀 | #Java #SlidingWindow #TwoPointers ✅ Problem Solved: Count the Number of Substrings With Dominant Ones (LeetCode) 🧩 Problem Summary: You’re given a binary string. A substring is dominant if: number of 1s > number of 0s × k (where k is given). Return the total count of such substrings. 💡 Approach Used: Used an optimized Sliding Window + Two Pointers approach: Traverse with a right pointer. Adjust the left pointer whenever the substring stops being dominant. All valid windows contribute (left + 1) substrings. This avoids brute-force O(N²) and makes the solution efficient. ⚙️ Time Complexity: O(N) 📦 Space Complexity: O(1) ✨ Takeaway: Sliding window transforms heavy substring problems into clean linear-time solutions. #Java #LeetCode #SlidingWindow #TwoPointers #ProblemSolving #CodingChallenge #100DaysOfCode
Solved LeetCode problem using Sliding Window and Two Pointers in Java.
More Relevant Posts
-
Day 29/100 – #100DaysOfCode 🚀 | #Java #LeetCode #BinaryTree ✅ Problem Solved: Verify Preorder Serialization of a Binary Tree 🌲 🧩 Problem Summary: Given a string representing a preorder serialization of a binary tree, determine if it’s valid. Example: "9,3,4,#,#,1,#,#,2,#,6,#,#" → ✅ valid "1,#" → ❌ invalid 💡 Approach Used: Used the slot-counting method 🧠 Each node uses one slot and non-null nodes create two new slots. Process the preorder string, ensuring slots never go negative and exactly zero remain at the end. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Takeaway: This problem teaches how binary tree structure can be validated with simple counting logic — no need to rebuild the tree! 🌱 #Java #LeetCode #BinaryTree #100DaysOfCode #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 40/100 – #100DaysOfCode 🚀 | #Java #LeetCode #TwoPointers #DynamicProgramming ✅ Problem Solved: Longest Palindromic Substring 🟣 🧩 Problem Summary: Given a string, return the longest palindromic substring within it. The substring must read the same forward and backward. 💡 Approach Used: Expand Around Center Technique Every palindrome is centered around: A single character (odd length) Or between two characters (even length) For each index: Expand left and right while characters match. Track the longest substring during expansions. This avoids unnecessary recomputation and works efficiently. ⚙️ Time Complexity: O(n²) 📦 Space Complexity: O(1) ✨ Takeaway: Sometimes, the cleanest approach comes from observing patterns — in this case, symmetry around a center 🎯 #Java #LeetCode #TwoPointers #ExpandAroundCenter #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode #344 — Reverse String (Two Pointer Approach) Solved this classic problem today! The task is simple: reverse a string in-place using O(1) extra memory — perfect for practicing the two-pointer technique. 💡 Idea: Use two pointers — one at the start and one at the end. Swap characters while moving both pointers toward the center. #LeetCode #Java #TwoPointer #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 48/100 – #100DaysOfCode 🚀 | #Java #Backtracking #Recursion ✅ Problem Solved: Palindrome Partitioning (LeetCode 131) 🧩 Problem Summary: Given a string s, partition it such that every substring in the partition is a palindrome. Return all possible palindrome partitioning combinations. 💡 Approach Used: Used Backtracking to explore all possible substring splits. Key Idea: At each position, expand and check if the substring s[start…i] is a palindrome. If yes → include it and recurse for the rest of the string. If no → skip and continue searching. Helper Components: Recursive DFS function for exploring partitions. A fast palindrome-checking utility. ⚙️ Time Complexity: O(N × 2ⁿ) 📦 Space Complexity: O(N) (recursion stack + path building) ✨ Takeaway: This problem strengthens understanding of recursion tree exploration, decision branching, and string-based backtracking. #Java #LeetCode #Backtracking #Recursion #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 85 Delete the Middle Node of a Linked List Problem Statement: Given the head of a singly linked list, delete the middle node and return the modified list. My Approach: Used two-pointer technique (slow & fast) to identify the middle node in a single traversal. Maintained a prev pointer to skip the middle node without extra space. Carefully handled the edge case when the list has only one node. Complexity: Time: O(N) Space: O(1) Linked lists are all about pointers and precision a small mistake (like an extra semicolon ";") can make a huge difference. Understanding how slow and fast pointers move gives deep insight into efficient traversal patterns. #LeetCode #100DaysOfCode #Java #LinkedList #ProblemSolving #takeUforward #CodingJourney #DataStructures #CodeNewbie
To view or add a comment, sign in
-
-
🔹 Day 46: Is Subsequence (LeetCode #392) 📌 Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is formed by deleting some (possibly none) characters from the original string without disturbing the relative order of the remaining characters. ✅ My Approach: I used a two-pointer technique — one pointer iterates through string t, and the other tracks progress through string s. Each time a matching character is found, the pointer for s moves forward. If we reach the end of s, it means all its characters appeared in sequence within t. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 2 ms (Beats 68.53%) Memory: 41.32 MB (Beats 87.28%) 💡 Reflection: A simple yet elegant problem that highlights how pointer movement can efficiently handle string comparisons without extra memory usage. ✨ #LeetCode #Java #Strings #TwoPointers #100DaysOfCode #Day46
To view or add a comment, sign in
-
-
💡 LeetCode #344 — Reverse String Today I solved LeetCode Problem 344: Reverse String 🔁 Problem Summary: Write a function that reverses a string. The input string is given as a character array s, and you must reverse it in-place (without using extra space). Key Idea: Use the two-pointer technique 👈👉 Initialize one pointer at the start (left) and another at the end (right). Swap the characters at both pointers and move them toward the center. #LeetCode #Java #DSA #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 91 Delete All Occurrences in a Doubly Linked List Given a doubly linked list and a key x, the task is to remove every node whose value equals x, and return the updated list. Example: Input: 2 <-> 2 <-> 10 <-> 8 <-> 4 <-> 2 <-> 5 <-> 2 Key: 2 Output: 10 <-> 8 <-> 4 <-> 5 My Approach Traversed the list using a pointer temp. For every node where temp.data == x: If it’s the head, shifted the head forward. Otherwise, re-linked the previous and next nodes to bypass the current one. Continued until the end of the list. Time Complexity: O(N) Space Complexity: O(1) Working with doubly linked lists reinforces how important pointer handling is. A single wrong link can break the entire structure but clean logic leads to elegant solutions! #100DaysOfCode #Java #DSA #LinkedList #GeeksforGeeks #ProblemSolving #CodingJourney #TakeUForward #CodeNewbie #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Inheritance (Java) Inheritance is a mechanism where a new class (subclass or derived class) inherits properties and behaviors from an existing class (superclass or base class). It promotes code reusability and establishes an 'is-a' relationship between classes. Subclasses can override methods from the superclass to provide specialized implementations. Inheritance supports the creation of class hierarchies, making the code more organized and maintainable. It's a powerful tool for modeling real-world relationships and reducing code duplication. #Java #JavaDev #OOP #Backend #professional #career #development
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