Day 36 / 100 – Longest Palindromic Substring (LeetCode #5) Today’s challenge focused on String Manipulation — finding the longest palindromic substring within a given string. At first, it felt tricky to handle all the possible substrings, but then I learned to expand around the center, checking for symmetry on both sides. This approach makes the solution both logical and efficient. This problem reinforced how clarity in logic often comes from recognizing patterns, and that even complex problems can be broken into smaller, mirror-like checks. 🔍 Key Learnings Expanding around the center efficiently checks for palindromes in O(n²) time. Always consider both even and odd length palindromes. String problems often rely on clear thinking more than heavy algorithms. 💭 Thought of the Day Problem-solving isn’t about rushing for the answer — it’s about exploring the structure of the challenge. Palindromes taught me patience, symmetry, and the art of looking for balance in both logic and code. 🔗 Problem Link: https://lnkd.in/gSe-ygD8 #100DaysOfCode #Day36 #LeetCode #Python #StringManipulation #ProblemSolving #Algorithms #CodingChallenge #CleanCode #CodeEveryday #LearningJourney #DataStructures #Optimization
Solved LeetCode #5: Longest Palindromic Substring with Python
More Relevant Posts
-
DAY-1:CODING CHALLENGE 1.Longest common Prefix substring from given string as input 2.3SUM problem Started with BRUTE-FORCE → checked every triplet. 😀 Worked 😇 but SLOW for big arrays (O(n³)) → TIME LIMIT EXCEEDED. Faced errors along the way: 'int object not iterable' → I wrote sorted(a,b,c) instead of sorted([a,b,c]). 'unhashable type: list' → Tried adding list to set. Fixed by converting to tuple. LOGICAL BUG → Return inside the loop returned early. Fixed by moving return outside. Finally moved to OPTIMAL TWO-POINTER APPROACH: Sort array first. Use two pointers to find pairs for target -nums[i]. Skip duplicates carefully. Complexity reduced to O(n²). 💡 Lessons learned: small syntax mistakes can cause big errors, immutable types are key for sets, and proper pointer logic makes code efficient. #Python #Algorithms #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 3 of #100DaysofDSA Today’s focus was on the “Set Matrix Zeroes” problem — a classic array-matrix question that tests both logic and optimization thinking It began with the brute-force idea: storing all zero positions and then marking corresponding rows and columns later. It works but takes O(m × n) time and O(m + n) extra space. Next, then explored a better approach using two auxiliary arrays to track which rows and columns should be zeroed. This improved the clarity but still consumed additional memory and space. Finally, then to reduce the complexity I tackled the optimal solution, which achieves O(1) extra space by using the first row and first column of the matrix itself as markers. A small Boolean flag handles the edge case when the first row contains a zero. This subtle observation transforms the logic completely — turning a memory-heavy method into a clean in-place algorithm. It was a good reminder that optimization isn’t just about speed — it’s about finding elegance in constraints. #100DaysOfDSA #MatrixProblems #Optimization #SpaceComplexity #Python #ProblemSolving
To view or add a comment, sign in
-
-
💡 Merge Sorted Array — LeetCode #88 Today I practiced one of the most common array problems — Merge Sorted Array, a great example of the two-pointer technique and in-place manipulation. Problem: You’re given two sorted arrays: nums1 with extra space at the end nums2 with n elements The goal is to merge them into a single sorted array inside nums1, without using extra space. Key Idea (Pattern): ➡️ Instead of merging from the front, we start from the back. This avoids overwriting elements in nums1 and lets us fill it from the largest to smallest. Approach: Use three pointers: p1 → end of valid elements in nums1 p2 → end of nums2 p → last index of nums1 Compare elements from both arrays and insert the larger one at the end of nums1. Copy any remaining elements from nums2. Time Complexity: O(m + n) Space Complexity: O(1) Pattern Learned: Two Pointers (backward traversal for in-place merging) Related Problems: Move Zeroes, Sort Colors, Merge Intervals Every time I solve one of these classic problems, I realize how much coding interviews are about recognizing patterns — not memorizing solutions. 💭 #LeetCode #DSA #CodingInterview #Python #Arrays #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
Day 16 of #100DaysOfLeetCode Today’s problem focused on substring counting within binary strings and required an efficient approach to handle potentially large input sizes without generating every substring explicitly. 1. Number of Substrings With Only 1s The task was to count the total number of substrings that consist entirely of the character '1', with the final result taken modulo (10^9 + 7). Instead of constructing the substrings, the key insight is that each continuous block of 1s contributes a predictable number of valid substrings. 🔹 My Approach: Iterated through the string while tracking the current streak length of consecutive 1s. Each time a block ended, computed the number of substrings from that block using the formula: k*(k+1)/2 where k is the length of the streak. Added the total from each block to the final answer, applying the modulo constraint throughout. Completed the process with a final update for any trailing block of 1s. What I Learned: This problem reinforces how recognizing mathematical patterns within sequences can transform a brute-force solution into a simple linear scan. Efficient substring counting often comes down to understanding structure rather than enumerating possibilities. 📊 Complexity Analysis: Time Complexity: O(n) — single pass over the string. Space Complexity: O(1) — constant space approach. #day16 #100daysofleetcode #leetcode #DSA #python #leetcodes #striver
To view or add a comment, sign in
-
-
🚀 LeetCode #1625: Lexicographically Smallest String After Applying Operations Today’s problem was about transforming a numeric string using two operations: adding a value to digits at odd indices and rotating the string, to get the lexicographically smallest result possible. The challenge was to handle infinite possibilities smartly. I used a Breadth First Search (BFS) approach to systematically explore all reachable string states while keeping track of visited ones. 💡 Key Takeaways: - Some problems don’t need a direct formula, they need systematic exploration. - BFS is not just for graphs; it’s a powerful tool for exploring state transitions too. - Modular arithmetic and rotation logic often come together in string manipulation problems. This one was a great reminder that clean logic and state tracking can solve even the most “infinite looking” problems efficiently. #LeetCode #ProblemSolving #Python #DSA #CodingChallenge #Algorithms #BFS #StringManipulation #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 82 of #100DaysOfDSA 🚀 Solved LeetCode 8 — String to Integer (atoi) 🔹 Problem: Implement the atoi function which converts a string to a 32-bit signed integer, handling whitespace, optional signs, and overflow conditions. 🔹 Approach: Used String Manipulation + Edge Case Handling 1️⃣ Trim leading and trailing whitespaces using strip(). 2️⃣ Check for optional '+' or '-' sign and store it. 3️⃣ Iterate through the string, building the integer digit by digit until a non-digit character appears. 4️⃣ Clamp the result to fit within 32-bit integer bounds [-2³¹, 2³¹−1]. ✨ Key Insight: Careful handling of edge cases and boundaries is crucial in string-to-integer problems — it’s all about precision and attention to detail. #LeetCode #DSA #Python #ProblemSolving #StringManipulation #CodingJourney #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
💡 Day 37 of 100 — Minimum Operations to Convert All Elements to Zero (#LeetCode 3542) Today’s problem was an interesting one short in code, but deeper in logic. It was one of those problems where the intuition slowly unfolds as you play with examples. 🧠 What I figured out This problem is all about monotonic stacks a pattern that helps you process elements in increasing or decreasing order efficiently. The key idea: Every time the current number is greater than what’s on top of the stack, it represents a new “operation” needed. By maintaining a non-decreasing stack, you avoid unnecessary repetitions and count exactly when new operations are required. 💻 My thought process At first, I tried to simulate each operation directly which got messy. Then I realized this could be solved cleanly using a stack that tracks when a new increase appears in the sequence. Every rise means one more operation, and when numbers fall, you just pop from the stack. 📊 Complexity: Time — O(n) Space — O(n) 💬 Reflection This one reminded me how often elegant ideas hide in short problems. It’s not about long code it’s about clarity of thought. Sometimes, a single stack can tell the whole story. #100DaysOfLeetCode #Day37 #LeetCodeJourney #Coding #ProblemSolving #Python #DSA
To view or add a comment, sign in
-
-
🚀 Day 40 of #100DaysOfDSA Solved LeetCode Problem #69 – Sqrt(x) 🧮 💡 Problem Insight: Given a non-negative integer x, return the square root of x rounded down to the nearest integer. For example: Input: x = 8 Output: 2 (since √8 ≈ 2.828, and floor(2.828) = 2) ✨ Key Learnings: Practiced binary search to find results efficiently without using built-in math functions. Learned how to narrow down search space based on mid-square comparisons. Reinforced understanding of integer division and rounding down behavior. Time Complexity: O(log n) — fast and efficient! Space Complexity: O(1) 💬 Lesson: Binary Search isn’t just for sorted arrays — it’s a mindset for narrowing down possibilities quickly 🚀 #LeetCode #Python #DSA #BinarySearch #ProblemSolving #100DaysOfCode #Day40 #CodingJourney
To view or add a comment, sign in
-
-
🧠 Day 13 — Thinking in Ranges, Not Just Numbers Today’s LeetCode problem was “Maximum Frequency of an Element After Performing Operations I.” At first, it felt straightforward — perform up to numOperations changes on elements within a range of [-k, k] to maximize frequency. But once I got into it, I realized the real challenge wasn’t the operations — it was understanding how intervals overlap and interact. Here’s the logic I built around it: 🔹 Each number can shift within [num - k, num + k], forming a range of possible values. 🔹 The goal is to find how many such ranges overlap at any point — that overlap represents the maximum achievable frequency. 🔹 I used sorted events and a sweep line approach to track how many intervals are active at any moment. 🔹 The maximum overlap gives the answer — the highest number of elements that can become equal after allowed operations. This problem wasn’t just about code; it was about thinking visually — seeing numbers as segments on a line rather than static values. That shift in perspective changed how I approached it. Thanks to Shishir chaurasiya sir and PrepInsta team One more day, one more layer of understanding peeled back. #Day13 #LeetCode #ProblemSolving #100DaysOfCode #Python #Algorithms #DataStructures #KeepBuilding #DevMindset
To view or add a comment, sign in
-
-
I recently revisited a project I built a while back, a 𝗣𝘆𝘁𝗵𝗼𝗻 𝘀𝗼𝗹𝘃𝗲𝗿 for the Bridges (Hashiwokakero) puzzle. 🧩 For those who haven’t seen it, Bridges is a logic puzzle where you connect islands with bridges according to specific rules. The idea came from a weekly tradition with my mum, solving the puzzle together over lunch. After we got pretty good at it, I got curious: could I teach a computer to do this too? What started as a fun side project turned into a deeper dive into algorithms and search optimisation, using recursive backtracking and graph-based connectivity checks. It’s a simple project, but one that means a lot to me. 🔗 Check it out here: https://lnkd.in/eJ_jwwud I’ve also attached a short video showing the solver in action, just terminal output, but it’s fun to see it work! #Python #Algorithms #ProblemSolving
To view or add a comment, sign in
Explore related topics
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