Day 28 of #100DaysOfCode: #DSA: Solve leetcode problem - Longest Palindrome(409) A palindrome string can be even/odd length so if the frequencies of letters are: 1. Even - we can use all of them to create palindrome string 2. Odd: - we can use frequency - 1 witch becomes even - we can leave one character for the middle approach: - hashmap to track freq of letters - iterate to the string - if freq is even just add to result - if freq is odd then add (freq - 1) to result - now in the last check - if hashmap contains only even freq return result - else return (result + 1) for middle character #Coding #Learing #CodingJourney
Longest Palindrome Solution on LeetCode
More Relevant Posts
-
🔥Day 16 - #GeekStreak60 ➡️Smallest window containing all characters Solved the Minimum Window Substring problem today using the Sliding Window technique. Problem: Given two strings s and p, find the smallest substring in s that contains all characters of p (including duplicates). Key Idea: Use two pointers to maintain a sliding window and a frequency map to track required characters. Expand the window to include characters and shrink it whenever all required characters are present to maintain the minimum length. Complexity: • Time: O(n) • Space: O(1) Sliding window problems really highlight how powerful two-pointer techniques can be when combined with frequency tracking. #gfg #npci #potd #dsa #coding #ProblemSolving #GfG60DaysChallenge #GeeksForGeeks
To view or add a comment, sign in
-
-
🧵 Day 11/31: Isomorphic Strings Two strings are isomorphic if characters can be replaced to get the second string. Example: "egg" → "add" ✅ | "foo" → "bar" ❌ Solution: Maintain two arrays of size 256 to track last seen positions. If last seen positions don't match → not isomorphic. Time: O(n) | Space: O(1) Another one down! 💪 #geekstreak60 #npci #Coding #ProblemSolving #GeeksforGeeks @geeksforgeeks @NPCI_NPCI
To view or add a comment, sign in
-
-
🚀 Day 16/60 — LeetCode Discipline Problem Solved: Palindrome Number (Revision) Difficulty: Easy Today’s practice revisited a classic number-based problem — determining whether a given integer reads the same forward and backward. Even though the problem appears simple, it reinforces an important concept: recognizing symmetry in data and applying straightforward transformations to verify it efficiently. In this revision, the focus was on converting the integer into a comparable structure and checking whether the reversed representation matches the original value. 💡 Focus Areas: • Reinforced palindrome symmetry concepts • Practiced number-to-string transformations • Strengthened basic logical validation techniques • Focused on writing clear and readable code Consistent practice of even the simplest problems helps keep fundamental logic sharp and reliable. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Algorithms #ProblemSolving #Programming #CodingJourney #SoftwareEngineering #Developers #TechCareers
To view or add a comment, sign in
-
-
🚀 Day 10/60 — LeetCode Discipline Problem Solved: Longest Palindromic Substring (Revision) Difficulty: Medium Today’s session was dedicated to revisiting one of the most elegant string problems — finding the longest palindromic substring. This problem goes beyond basic traversal and demands a deeper understanding of symmetry, center expansion, and efficient substring handling. During this revision, the focus was on strengthening pattern recognition and writing an optimized solution with clean logic. 💡 Focus Areas: • Deepened understanding of palindrome symmetry • Strengthened string transformation and center-based reasoning • Practiced handling odd vs even length palindromes • Focused on improving time complexity awareness • Emphasized clean and maintainable implementation ⚡ Performance Highlight: Achieved ~97% runtime efficiency on submission. Consistent revision of classical problems is steadily improving my pattern recognition and algorithmic confidence. The journey continues with sharper intuition and stronger fundamentals each day. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Palindrome #Algorithms #DataStructures #ProblemSolving #CodingJourney #SoftwareEngineering #TechCareers #Programming #Developers #CodingLife
To view or add a comment, sign in
-
-
20 of #100DaysOfCode Solved LeetCode 438 – Find All Anagrams in a String using the Sliding Window Technique. 🔹 Approach (Optimal – Sliding Window): Used frequency arrays and a fixed window of size k to track character counts efficiently. Time Complexity: O(n) Space Complexity: O(1) 💡 Key Learning: Sliding Window helps reduce repeated computation when dealing with contiguous subarrays/substrings. 📌 Always look for patterns where a fixed-size window can optimize brute force solutions. #leetcode #coding #cpp #datastructures #algorithms #programming #softwareengineering #slidingwindow #dsa #100DaysOfCode
To view or add a comment, sign in
-
-
Day 48 on LeetCode Minimum Size Subarray Sum 🎯✅ Today’s problem was a perfect application of the Sliding Window technique for optimizing subarray problems. 🔹 Approach Used in My Solution The goal was to find the smallest subarray length whose sum is greater than or equal to the target. Key idea in the solution: • Use two pointers low and high to maintain a dynamic window • Expand the window by moving high and adding elements to currentSum • Once the sum becomes ≥ target, start shrinking the window from the left (low) • Continuously update the minimum length during this process • If no valid subarray is found, return 0 This approach avoids brute force and ensures we process each element at most twice. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered the Sliding Window technique for variable window size • Learned how to optimize subarray problems from O(n²) to O(n) • Reinforced handling dynamic window expansion and contraction #LeetCode #DSA #Algorithms #DataStructures #SlidingWindow #Arrays #TwoPointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Daily Vim tip: Use f{char} / F{char} to move the cursor at a specific character on the current line. f jumps forward to it; F hunts backward. After the first jump, ; repeats in the same direction and , reverses — so you can skip through multiple matches without retyping. Learn more: run `vimtutor` in your terminal, or use `:help f{char}` inside Vim. #vim #vimtip #coding
To view or add a comment, sign in
-
-
🚀 Day 11 of #LeetCodeConsistency Today I solved Number of Steps to Reduce a Number in Binary Representation to One 💻 This problem focuses on reducing a binary number to 1 using two operations: ✔️ If the number is even → divide by 2 ✔️ If the number is odd → add 1 A key insight was realizing that converting the binary string to an integer is unnecessary (and inefficient for large inputs). Instead, the problem can be solved optimally by traversing the binary string from right to left while simulating carry propagation, similar to binary addition. This allows us to count operations in a single pass without modifying the string. 🔎 What I learned today • How division by 2 in binary corresponds to pointer movement • Importance of carry-based simulation for big-number problems • A classic pattern applicable to string addition and bit manipulation questions ✅ Implemented an O(n) time and O(1) space solution ✅ Strengthened my understanding of binary simulation patterns 📌 Check out my solution here: https://lnkd.in/dzsegVhV Consistency compounds — excited to keep learning and improving every day 💪 #LeetCode #DSA #ProblemSolving #Coding #SoftwareEngineering #BitManipulation #100DaysOfCode
To view or add a comment, sign in
-
-
k-th Lexicographical Happy String of Length n🪢 Given n and k, return the k-th lexicographical happy string of length n. Thought process Brute force idea: Generate all possible happy strings of length n, Sort them, Return the string at k-1 index Optimization Instead of generating everything and sorting later, we can control the order while generating. During backtracking: Try characters in order → a, b, c Skip if the current character is the same as the previous one This way strings are already generated in lexicographical order, so we can directly return the k-th string. #leetcode #thoughtProcess #problemSolving #programming #recursion #backtracking
To view or add a comment, sign in
-
-
Day 61 – Remove Duplicate Letters: Building the Smallest Lexicographical Sequence 🔤📊 Today's challenge was a masterclass in greedy algorithms and stack based decision making removing duplicate letters from a string while preserving the relative order and ensuring the smallest lexicographical result. 🔤 Remove Duplicate Letters I approached this problem using a monotonic stack combined with frequency tracking and visited flags. First, I counted the frequency of each character in the string. Then, while iterating through each character, I decremented its count and, if it was already in the stack, simply skipped it. When encountering a new character, I popped characters from the stack if they were greater than the current character and still had remaining occurrences later in the string. Finally, I pushed the current character onto the stack and marked it as visited. This greedy approach achieved O(n) time with O(1) space for the fixed alphabet size. #LeetCode #Coding #Algorithms #DataStructures #Stack #Greedy #StringManipulation #Lexicographical #ProblemSolving #SoftwareEngineering #Programming #100DaysOfCode
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
Without hashmaps this is so tricky