DSA Practice – Palindrome String Check :- Approach Used: I implemented the two-pointer technique by comparing characters from the start and end of the string, moving towards the center. If any characters do not match, the string is not a palindrome. Otherwise, it is a palindrome. Time Complexity: O(n) Space Complexity: O(1) #JAVA #DSA
Palindrome String Check with Two-Pointer Technique
More Relevant Posts
-
Day 44 of DSA 🚀 Solved Minimum Number of Flips to Make the Binary String Alternating. 💡 Key Insight: An alternating binary string can only follow two patterns: 010101... 101010... To handle rotations efficiently: Double the string (s + s) Use a sliding window of size n Count mismatches with both patterns Track the minimum flips required. ⏱ Time: O(n) 💾 Space: O(n) Good practice for sliding window + pattern matching. #DSA #Java #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
📌 Day 15 – GFG Problem of the Day 🧩 Number of Submatrix with Sum X Given a matrix and an integer X, find the number of square submatrices whose sum of elements is equal to X. 💡 Key Insight: Using prefix sum for 2D matrices allows us to compute the sum of any square submatrix in constant time after preprocessing. ✨ Approach: • Build a 2D prefix sum matrix • For every possible top-left corner, try all square sizes • Use prefix sum formula to calculate submatrix sum efficiently • If sum equals X, increase the count ⏱ Time Complexity: O(n³) 📦 Space Complexity: O(n²) This problem shows how extending the prefix sum idea from 1D to 2D helps in solving complex matrix sum problems efficiently. #GeeksforGeeks #ProblemOfTheDay #DSA #Java #Matrix #PrefixSum #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 38 / 100 | Merge Close Characters -Intuition: -The idea is that if the same character appears within distance k, the right character merges into the left. -So we only keep characters that cannot be merged with any previous same character within range k. -Approach: O(n²) -Create a StringBuilder to store the result. -Traverse each character in the string. -For each character, check in the result string if the same character exists within distance k from the end. -If found, it merges (ignore current character). -Otherwise, append it to the result. -Final StringBuilder will be the answer after all merges. -Complexity: Time Complexity: O(n²) Space Complexity: O(n) #100DaysOfCode #Java #DSA #LeetCode #String
To view or add a comment, sign in
-
-
Day 61: Grid Lock 🧩 Problem 1536: Minimum Swaps to Arrange a Binary Grid Today was about cleaning up a binary grid to satisfy a specific condition: all elements above the main diagonal must be zero. The catch? You can only swap adjacent rows. I tackled this by first converting each row into a single integer representing its count of trailing zeros. This turned a complex 2D grid problem into a 1D greedy search. For each position in the grid, I looked for the first available row that met the zero-count requirement, added the "distance" to my swap total, and removed that row from the pool. It’s essentially a selection sort logic where you only care about the trailing zeros. If you hit a point where no row in the remaining list fits the bill, it’s an immediate -1. Clean, greedy, and efficient enough to keep the streak rolling. 🚀 #LeetCode #Java #GreedyAlgorithms #Matrix #Coding #DailyCode
To view or add a comment, sign in
-
-
Day 96 of my 100 Days of LeetCode Challenge 🚀 Solved Find All Anagrams in a String — another strong Sliding Window problem focused on frequency counting. The task is to find all starting indices of substrings in s that are anagrams of string p. Approach used: • If p is longer than s, return empty list • Use two frequency arrays of size 26 (for lowercase letters) • Initialize the first window of size p.length() • Slide the window across s • Update frequencies by removing the left character and adding the right character • Compare frequency arrays at each step Time Complexity: O(n) Space Complexity: O(1) This problem strengthens understanding of fixed-size sliding windows and efficient frequency comparison. #100DaysOfCode #100DaysOfLeetCode #LeetCode #SlidingWindow #Arrays #Strings #Java #DSA #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
Day 2/75 — Valid Palindrome (Two Pointers Pattern) Today’s problem looked simple, but the real challenge was handling edge cases. Problem: Valid Palindrome Instead of creating a new cleaned string, I used the two-pointer approach: • One pointer from the start • One pointer from the end • Skip non-alphanumeric characters • Compare characters in lowercase Time Complexity: O(n) Space Complexity: O(1) Key Insight: When comparing symmetry in strings, two pointers are often more efficient than building extra strings. Also learned how important it is to carefully handle character validation using Character.isLetterOrDigit(). Small problems like this sharpen attention to detail. 2/75 — staying consistent. #Day2 #75DaysChallenge #DSA #Java #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
Day 94 of my 100 Days of LeetCode Challenge 🚀 Solved Permutation in String — a great Sliding Window + HashMap problem. The task is to check whether any permutation of s1 exists as a substring in s2. In other words, we need to determine if s2 contains a substring with exactly the same character frequency as s1. Approach used: • If s1 is longer than s2, return false immediately • Use two HashMaps to track character frequencies • Initialize the first window of size s1.length() • Slide the window across s2 • Update counts dynamically (add right char, remove left char) • Compare frequency maps at each step Time Complexity: O(n) Space Complexity: O(1) (since character set is limited) This problem strengthens understanding of fixed-size sliding windows and frequency matching techniques. #100DaysOfCode #100DaysOfLeetCode #LeetCode #SlidingWindow #HashMap #Strings #Java #DSA #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 23 of #100DaysOfCode 🌱 Topic: Strings / Hashing / Sliding Window ✅ Problem Solved: LeetCode 1461 – Check If a String Contains All Binary Codes of Size K 🛠 Approach: Generated all substrings of length k using sliding window. Stored each substring inside a HashSet to track uniqueness. Compared set size with 2^k to check if all possible binary codes exist. Used bit manipulation concept (1 << k) to calculate total combinations. ⏱ Time Complexity: O(n * k) 📦 Space Complexity: O(2^k) #100DaysOfCode #Day23 #DSA #Strings #Hashing #BitManipulation #Java #LeetCode #ProblemSolving #CodingJourney #Consistency #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 18/30 – LeetCode streak Problem: Special Positions in a Binary Matrix A position '(i, j)' is special if 'mat[i][j] == 1', and every other element in row 'i' and column 'j' is '0'. Core idea - Precompute how many '1's each row and each column contains. - Then a cell '(i, j)' is special if: - 'mat[i][j] == 1' - 'rowSum[i] == 1' - 'colSum[j] == 1'. - Time: 'O(m × n)' – one full pass to compute sums, one to count special cells. - Space: 'O(m + n)' for 'rowSum' and 'colSum'. Day 18 takeaway: This is a clean pattern: precompute per-row and per-column counts once, then answer each cell’s question in 'O(1)' using those arrays instead of re-scanning its whole row and column. #leetcode #dsa #java #matrix #consistency
To view or add a comment, sign in
-
-
Day 17 - Container With Most Water Technique Used: Two-Pointer Optimization Key Idea: Initialized pointers at both ends of the array and computed the area using min(height[left], height[right]) × (right - left). Moved the pointer at the smaller height inward to potentially increase the area. Time Complexity: O(n) #Day17 #LeetCode #Java #TwoPointers #DSA
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