📅 Day 68 of #100DaysOfLeetCode 🧩 Problem: 1312. Minimum Insertion Steps to Make a String Palindrome 💪 Difficulty: Hard 🧠 Key Insight To make a string a palindrome using minimum insertions, we should preserve the longest palindromic subsequence (LPS) and insert characters around it. 💡 Important Observation: The Longest Palindromic Subsequence (LPS) of a string = Longest Common Subsequence (LCS) between the string and its reverse 📌 Formula: Minimum Insertions = n − LPS ⏱️ Complexity Time: O(n²) Space: O(n²) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Minimum Insertions to Make String Palindrome
More Relevant Posts
-
This problem uses a modified Binary Search to find a target in a rotated sorted array in O(log n) time. Key Idea: Even after rotation, one half of the array is always sorted. By identifying the sorted half and checking if the target lies within it, we can eliminate half of the search space in every step. => Time Complexity: O(log n) => Space Complexity: O(1) Great problem to strengthen binary search fundamentals and edge-case handling. #BinarySearch #Array #DivideAndConquer #LeetCode #DSA #InterviewPreparation #Java
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode Today’s problem focused on combining string processing + two pointers — 🔍 LeetCode 125: Valid Palindrome A great example of how small edge cases can make a simple problem interesting. 📌 Problem Summary Given a string s, determine whether it is a palindrome by: Ignoring non-alphanumeric characters Treating uppercase and lowercase letters as the same 🧠 Approach Used: Two Pointers ✔️ Initialize two pointers: left at the start right at the end ✔️ Skip non-alphanumeric characters ✔️ Compare characters in a case-insensitive manner ✔️ Move inward until pointers meet If all comparisons match → it’s a palindrome ✅ ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) ✔️ 488 / 488 test cases passed 🚀 Runtime: 2 ms (Beats ~99%) 🔥 Key Learning This problem reinforces: Two-pointer technique on strings Careful handling of edge cases Writing clean helper functions for readability Simple logic + correct filtering = solid solution 💪 Onward to Day 59 🚀 #100DaysOfCode #LeetCode #ValidPalindrome #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 22 – LeetCode 3 Longest Substring Without Repeating Characters Solved using Sliding Window + HashMap. Instead of checking all substrings (O(n²) ❌), I maintained a window of unique characters and jumped the left pointer whenever a duplicate appeared. Time Complexity: O(n) Space Complexity: O(1) Key takeaway: Most substring problems are solved using sliding window patterns, not brute force. Day 22/90 consistency streak continues 🔥 #leetcode #dsa #slidingwindow #java #softwareengineering
To view or add a comment, sign in
-
🚀 Day 77 of #100DaysOfLeetCode 📌 Problem: 1877. Minimize Maximum Pair Sum in Array 📊 Difficulty: Medium 🧠 Key Insight: To minimize the maximum pair sum, pair the smallest element with the largest, the second smallest with the second largest, and so on. This balances the sums and avoids any single pair becoming too large. ⚙️ Approach: Sort the array Use two pointers: i starting from the beginning j starting from the end Pair nums[i] + nums[j] and track the maximum sum Move both pointers inward until all pairs are formed ⏱️ Complexity: Time: O(n log n) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day 3 | Problem 2 – Palindrome String Today I practised checking whether a string is a palindrome using basic two-pointer logic. Approach used: • Start comparing characters from the left and right ends • If characters match, move both pointers inward • If any mismatch occurs, the string is not a palindrome • If the loop completes, the string is a palindrome This problem helped me understand string traversal, indexing, and conditional logic more clearly. #Java #DSA #StringProblems #LearningInPublic
To view or add a comment, sign in
-
-
Hello Everyone, Day 13 / #100DaysOfCode LeetCode 3453 — Separate Squares I (Medium) Problem: Given multiple axis-aligned squares on a 2D plane, find the minimum y-coordinate of a horizontal line such that the total area above the line equals the total area below it. Overlapping areas are counted multiple times. Approach: - Observed that the area difference (above − below) changes monotonically as the line moves up - Applied binary search on the y-coordinate - For each candidate height, computed how much area of every square lies below the line and compared it with the total area Key insight: Once the monotonic behavior is identified, the problem reduces to a clean binary search on the answer space. #LeetCode #DSA #Java
To view or add a comment, sign in
-
-
🔹 Day 85 – #100DaysOfLeetCode Problem: 3010. Divide an Array Into Subarrays With Minimum Cost I Difficulty: Easy Key Insight: The cost of a subarray depends only on its first element. Since the first subarray always starts at index 0, the problem reduces to selecting the two smallest possible starting elements from the remaining array. Approach: Fix the first subarray cost as nums[0] Find the smallest and second smallest values in nums[1…n-1] Add them to get the minimum total cost Time Complexity: O(n) Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟴/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved Find Missing Elements by combining HashSet + Range Traversal. ➤ Approach • First pass: — Find min and max in the array — Store all elements in a HashSet • Second pass: — Traverse from min to max — Add numbers not present in the set to the result list ➤ Key Insight: Since the smallest and largest values are guaranteed to exist, the missing numbers must lie within that range. #LeetCode #Java #DSA #TwoPointers #ArrayManipulation #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
Day 22 of #30DaysDSAChallenge 🚀 Today’s problem: String Compression (LeetCode) 🔹 Problem Statement: Given an array of characters, compress it in-place such that consecutive repeating characters are replaced by the character followed by the count. 🔹 Approach I used: Traverse the array using two pointers. Count consecutive characters. Update the same array with: the character followed by its frequency (if > 1) Return the new length of the compressed array. 🔹 Key Learnings: How to work with in-place array modification. Efficient use of two pointers. Converting integers to characters while updating arrays. Importance of space optimization (O(1) extra space). 📈 Result: All test cases passed successfully! Consistency > Motivation. One problem every day, getting better step by step 💪 #Day22 #DSA #LeetCode #StringCompression #Java #CodingJourney #100DaysOfCode #SoftwareEngineer #ProblemSolving #MCA
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