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
Checking Palindromes with Java Two-Pointer Logic
More Relevant Posts
-
🚀 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
-
-
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
To view or add a comment, sign in
-
-
Day 5 | Problem 1 – Score of a String Today I practised calculating the score of a string by finding the absolute difference between adjacent characters. Approach used: • Traverse the string from left to right • Calculate the absolute ASCII difference between consecutive characters • Add each difference to a running sum • Return the final score This problem helped me better understand character handling in strings, ASCII values, and loop-based traversal. #Java #DSA #StringProblems #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
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
-
-
𝗗𝗮𝘆 𝟴/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 🎯 LeetCode 3 – Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without duplicate characters. ➤ Approach: We use the sliding window technique to dynamically track the current substring and adjust it whenever a duplicate is found. A HashMap is used to store the last seen index of each character for quick lookups. - Use two pointers (left & right) to define the current window. - Move right forward, tracking characters and their last seen index. - If a duplicate is found within the window, move left to just after the previous occurrence. - Continuously update the maximum length found. This ensures each character is processed at most twice, making the approach highly efficient. ➤ Key Insight: By using the HashMap to remember the last index of characters, we avoid re-checking parts of the string — a prime example of turning a brute-force O(n²) problem into an O(n) solution. ➤ Time Complexity: O(n) ➤ Space Complexity: O(min(n, charset size)) #LeetCode #Java #DSA #TwoPointers #ArrayManipulation #ProblemSolving #20DaysChallenge #Consistency
To view or add a comment, sign in
-
-
🚀 Day 89 of #100DaysofLeetCode Problem: Minimum Size Subarray Sum Difficulty: Medium Today’s challenge was about finding the smallest length subarray whose sum is greater than or equal to a given target. Since all elements are positive, this problem is a perfect fit for the Sliding Window technique. Instead of checking all possible subarrays (which would be inefficient), I used two pointers: Expand the window by moving the right pointer and adding to the current sum. Once the sum becomes ≥ target, shrink the window from the left to find the minimum possible length. Keep updating the minimum length during this process. Key takeaways: Positive integers allow efficient window shrinking. Two pointers help reduce time complexity from O(n²) to O(n). Maintain a running sum and dynamically adjust window size. Return 0 if no valid subarray exists. Time Complexity: O(n) Space Complexity: O(1) Another solid sliding window problem completed 💪 #100DaysOfCode #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingJourney #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 30 / 100 | First Missing Positive -Intuition: The smallest missing positive will always be in range 1 to n+1. Place each number at its correct index (1 at index 0, 2 at index 1 so on). First index where value ≠ index+1 gives the missing number. -Approach : O(n) Find length of array n Traverse array and place each element at correct position -> index = value − 1 Ignore negative numbers, zero, and numbers > n After placement, traverse array again If arr[i] ≠ i+1 -> return i+1 If all elements are correct -> return n+1 -Complexity: Time Complexity : O(n) Space Complexity : O(1) #100DaysOfCode #Java #DSA #Array #LeetCode
To view or add a comment, sign in
-
-
Day 19/30 – Palindrome Linked List 🚀 Problem: Check if a linked list is a palindrome. Approach: 1️⃣ Find middle using slow & fast pointers 2️⃣ Reverse second half 3️⃣ Compare both halves Why this approach? • O(n) time • O(1) space • No extra array Classic pointer manipulation + in-place reversal. #30DaysOfCode #Java #DSA #LinkedList #InterviewPrep
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
-
-
🚀 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
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