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
Solved Longest Palindromic Substring with Java and LeetCode
More Relevant Posts
-
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
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 71 String Rotation Task: Given two strings s and goal, determine if s can become goal after some number of rotations (moving the first character to the end each time). Example: Input: s = "abcde", goal = "cdeab" Output: true My Approach First, check if both strings have the same length otherwise, rotation is impossible. Then, observe that any valid rotation of s will always appear as a substring in s + s. Simply check: return (s + s).contains(goal); Time Complexity: O(N²) Space Complexity: O(N) Sometimes, elegant insights lead to minimal code doubling a string can reveal every possible rotation effortlessly! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringManipulation #takeUforward #GeeksForGeeks #CodeNewbie #InterviewPrep
To view or add a comment, sign in
-
-
💻 Day 30 🚀of #30DaysOfLeetCode Problem: Move Zeroes https://lnkd.in/gBYJphPM Language: Java ☕ 🧠 Logic: Traverse the array, move all non-zero elements forward, and fill remaining positions with zeros — all done in-place! ✅ Result: Runtime: 2 ms (Beats 79.18%) Memory: 46.02 MB (Beats 80.31%) 🗣️ “Optimization isn’t about speed alone — it’s about clean, efficient logic.” #LeetCode #Java #CodingChallenge #30DaysOfCode #ProblemSolving #MoveZeroes #Day30 #CodeDaily
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
-
-
🚀 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
-
-
#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 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
-
-
Problem: Final Value of Variable After Performing Operations Difficulty: Easy Sometimes coding challenges are not about complex algorithms — they’re about writing clean, readable logic. Today’s problem gives a list of increment/decrement operations (++X, X++, --X, X--) and asks to compute the final value of a variable starting from 0. Simple? Yes. But it's a good reminder that clarity > cleverness. #Day17 #LeetCode #Java #BeginnerFriendly #Consistency #100DaysOfCode #ProblemSolving #CodingJourney
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 67 Reverse Words in a String Problem: – Reverse Words in a String Task: – Given a string, reverse the order of the words and remove extra spaces. Example: Input: s = " the sky is blue " → Output: "blue is sky the" My Approach: Used trim() to remove leading and trailing spaces. Split the string using split("\\s+") to handle multiple spaces. Reversed the array and joined the words with a single space. Time Complexity: O(N) | Space Complexity: O(N) Even simple string problems can teach the importance of clean code and efficient use of built-in methods. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #CodeNewbie #StringManipulation
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