Day 49 of Daily DSA 🚀 Solved LeetCode 234: Palindrome Linked List ✅ Problem: Given the head of a singly linked list, return true if it is a palindrome, otherwise false. Approach: Used a stack-based method to compare linked list values from both directions. Steps: Traverse the linked list and push all node values into a stack Start again from head Pop values one by one from stack Compare current node value with popped value If mismatch found → return false If all match → return true ⏱ Complexity: • Time: O(n) • Space: O(n) 📊 LeetCode Stats: • Runtime: 15 ms • Memory: 101.66 MB Sometimes using extra space can make the logic cleaner and easier to implement. #DSA #LeetCode #Java #LinkedList #Stack #CodingJourney #ProblemSolving
Palindrome Linked List Solution in Java
More Relevant Posts
-
Continuing my DSA journey, * Problem: Number of Atoms (726) * Approach: -I solved this using a stack-based parsing approach. -I used a stack of maps to keep track of atom counts at different levels. While iterating through the string: -On '(' → push a new map onto the stack -On ')' → pop the top map, multiply counts, and merge back -For elements → parse the name and count, then update the current map * Key Insight: -The tricky part was handling nested parentheses and applying multipliers correctly. -Using a stack helps manage different scopes efficiently. * What I Learned: This problem improved my understanding of string parsing with stacks. #LeetCode #DSA #Java #Stack #Strings #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode Solved LeetCode 179 – Largest Number 🔢 Today’s problem was a great reminder that sorting isn’t always straightforward. Instead of normal numeric sorting, the trick is to compare numbers based on their string concatenation order. 💡 Key Insight: To decide order between two numbers a and b, compare: ab vs ba Whichever forms the larger number should come first. 🔍 What I learned: Custom sorting using comparators Converting integers to strings for flexible comparison Edge case handling (like leading zeros → return "0") ⚡ Approach: Convert integers to strings Sort using (b+a).compareTo(a+b) logic Build the final result using StringBuilder 💻 Efficient and clean solution with strong real-world relevance in greedy + sorting problems #100DaysOfCode #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #DSAwithEdSlash @edslash
To view or add a comment, sign in
-
-
The Two-Pointer streak continues! Today’s LeetCode Problem: Is Subsequence. After using multiple pointers to sort arrays and move zeroes, I applied the exact same pattern to string manipulation today. The challenge was figuring out if a shorter string (s) is a valid subsequence of a longer string (t) without disturbing the relative order of the characters. Instead of generating all possible subsequences (which would be a massive O(2ⁿ) performance drain), the Two-Pointer approach solves this beautifully in a single pass. Knocking this out in O(n) time and O(1) space is another great reminder of how incredibly versatile this algorithmic pattern is for both arrays and strings. #DSA #Java #LeetCode #IsSebsequenceProblem
To view or add a comment, sign in
-
-
🚀 Day 27/100 – LeetCode DSA Challenge 📌 Problem Solved: Find All Numbers Disappeared in an Array Today’s problem focused on identifying missing numbers from an array where elements are in the range [1, n]. 🔍 Approach I Used (Easy Method): Created a boolean array to track visited numbers Marked each number as present Iterated from 1 to n to find missing elements 💡 Key Concepts Learned: How to use index-based mapping for arrays Importance of range constraints [1, n] Difference between brute force vs optimized approach Using extra space to simplify logic 🧠 What I Understood Today: If a problem says numbers are in range [1, n], we can directly map values to indices Tracking frequency or presence is a powerful technique Writing clean and simple logic first is more important than jumping to optimization 🔥 Next Step: I will try the optimized approach (O(1) space) using index marking (negative marking technique) 📈 Improving step by step in DSA — consistency is the key! #Day27 #LeetCode #DSA #100DaysOfCode #CodingJourney #PlacementsPreparation #Java
To view or add a comment, sign in
-
-
🚀 Day 36 of my DSA Journey 📌 Problem: 560. Subarray Sum Equals K Given an array and a value k, we need to find how many subarrays (continuous parts of the array) add up to k. 💡 My Approach (Simple Explanation): Instead of checking all subarrays (which is slow), I used the prefix sum + HashMap trick. Keep adding elements to get a running sum Check if (current sum - k) was seen before If yes, it means a valid subarray exists Store prefix sums in a map to reuse quickly This makes the solution efficient ⚡ ✅ Result: Accepted ⏱ Runtime: 0 ms ✨ Small optimizations like this really show how powerful concepts can simplify problems! #Day36 #DSA #CodingJourney #Java #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
📅 Day 129/360 – DSA Journey Today’s focus: Palindrome Partitioning using Backtracking 🔁 This problem strengthened my grip on recursion and how to systematically explore all possible solutions. 💡 What I practiced today: Applying backtracking (choose → explore → backtrack) Checking substrings efficiently using a palindrome helper Building all valid partitions step by step ⚙️ Approach: At each index, try every possible substring. If it’s a palindrome → include it in the current path → move ahead → then backtrack to explore other possibilities. ⏱️ Time Complexity: O(2ⁿ × n) There are ~2ⁿ possible partitions For each partition, checking palindrome takes up to O(n) 📦 Space Complexity: O(n) (recursion stack) + O(k × n) (to store results) n → depth of recursion k → number of valid partitions 🧠 Key Takeaway: Backtracking is all about exploring every valid path while keeping the solution clean and reversible. Consistency continues 🚀 #Day129 #DSAJourney #Backtracking #Java #CodingPractice #TimeComplexity #SpaceComplexity
To view or add a comment, sign in
-
-
Day 47 of Daily DSA 🚀 Solved LeetCode 74: Search a 2D Matrix ✅ Problem: Given a sorted 2D matrix where: • Each row is sorted • First element of each row > last element of previous row Find whether a target exists in the matrix. Approach: Used an optimized staircase search (top-right traversal). Steps: Start from top-right corner If element == target → return true If element > target → move left If element < target → move down Continue until found or out of bounds ⏱ Complexity: • Time: O(n + m) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.84 MB Sometimes choosing the right starting point (top-right) makes the search super efficient 💡 #DSA #LeetCode #Java #Matrix #BinarySearch #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 80/90 Solved: Largest Rectangle in Histogram Core idea: → Use monotonic stack to find nearest smaller to left & right → Width = (right - left - 1), maximize area This is one of those problems where the pattern isn’t obvious at first. Once the left/right boundary logic clicks, the solution becomes systematic. #Consistency #DSA #LeetCode #Stack #MonotonicStack #ProblemSolving #Java #Algorithms
To view or add a comment, sign in
-
-
=>Day 17/90 DSA Journey Solved: Continuous Subarray Sum (LeetCode) Today I worked on an interesting problem involving Prefix Sum + HashMap, which helped me optimize from a brute-force O(n²) solution to an efficient O(n) approach. If the same remainder (sum % k) appears again, it means the subarray between those indices has a sum divisible by k. -> What I learned: How to use prefix sum effectively Importance of storing remainders in HashMap Handling edge cases like subarray length ≥ 2 ->Optimization: Brute Force → O(n²) ❌ Optimized Approach → O(n) ✅ #LeetCode #DSA #Java #Coding #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 72/100 Completed ✅ 🚀 Solved LeetCode – Matrix Diagonal Sum (Java) ⚡ Implemented an efficient approach to calculate the sum of both primary and secondary diagonals of a square matrix in a single traversal. Avoided double-counting the center element by handling the odd-sized matrix case separately. 🧠 Key Learnings: • Efficient diagonal traversal in a matrix • Handling overlapping elements (center in odd n) • Writing optimal O(n) solutions instead of nested loops • Clean and concise index-based logic 💯 This problem improved my understanding of matrix patterns and how to optimize traversal by reducing unnecessary iterations. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #arrays #problemSolving #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