✅ Solved: Palindrome Number — LeetCode #9 Accepted with all 11,511 / 11,511 test cases passed! 🎯 The problem asks: Given an integer x, return true if x is a palindrome, and false otherwise. My approach: Immediately return false for negative numbers (can't be palindromes) Convert the integer to a String using String.valueOf() Reverse the string by iterating from end to start Compare original and reversed — if equal, it's a palindrome ✔️ Runtime: 16 ms | Memory: 46.48 MB A clean beginner-friendly solution. Next, I'd like to optimize it using a mathematical digit-reversal approach — no String conversion needed, better memory efficiency! 🚀 If you're grinding LeetCode, don't skip the easy problems. They build the intuition you need for the hard ones. 💪 #LeetCode #Java #DSA #DataStructures #Algorithms #CodingChallenge #Programming #SoftwareDevelopment #ProblemSolving #PalindromeNumber
Palindrome Number LeetCode Solution
More Relevant Posts
-
🚀 Day 22 of 180 — Longest Substring Without Repeating Characters ✅ LeetCode 3 — Longest Substring Without Repeating Characters Classic sliding window problem. Find the longest substring with all unique characters. Used a HashMap to store each character with its last seen index instead of frequency. This is the key difference from previous sliding window problems. Slide r through the string. If current character already exists in map AND its last seen index is within current window (>= l) — move l to one position ahead of that last seen index. This way the duplicate is removed from the window. Then update the character's index in map and calculate max window size. The tricky part — even if character exists in map, only move l if that character is actually inside the current window. If it's behind l already, no need to shrink. Day 22 done. 158 to go. 🔥 #180DaysDSA #Day22 #LeetCode #Java #DSA #SlidingWindow #HashMap #Strings #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Second Largest Element Problem Sometimes the simplest problems teach the most important lessons 💡 🧩 Problem: Find the second largest element in an array 👉 If it doesn’t exist, return -1 ⚡ My Approach: Instead of sorting (which costs more time ⏳), I used: ✔ First pass → Find the largest element ✔ Second pass → Find the second largest (≠ largest) 📊 Complexity: ⏱ Time: O(n) 📦 Space: O(1) 🧠 Key Learnings: ✔ Avoid unnecessary sorting 🚫 ✔ Think in terms of optimization first ✔ Edge cases matter (e.g., [10,10,10]) 🔥 Result: ✅ 1120 / 1120 Test Cases Passed 🎯 100% Accuracy #leetcode #dsa #java #arrays #algorithms #coding #programming #developers #softwareengineering #problemSolving #tech #codingjourney #100daysofcode
To view or add a comment, sign in
-
-
🚀 Just crossed 130 LeetCode problems solved! Here are the 5 patterns that unlocked the majority of them: 1️⃣ Sliding Window — O(n) solutions hiding inside O(n²) problems 2️⃣ Two Pointers — eliminate the inner loop, think from both ends 3️⃣ BFS/DFS — once you see graphs everywhere, you can't unsee them 4️⃣ Dynamic Programming — break it into subproblems, trust the recurrence 5️⃣ Binary Search — not just for sorted arrays; think about "search space" Most medium problems are just combinations of these 5. The real milestone isn't the number — it's the moment you stop Googling the approach and start reasoning from first principles. Onto the next 130. 💻 #LeetCode #DataStructures #Algorithms #Java #DSA #Tech
To view or add a comment, sign in
-
-
Many developers use extra space (like HashMaps) to solve the majority element problem. But there’s a more optimal approach Moore’s Voting Algorithm. - O(n) time, O(1) space - Uses a candidate + count mechanism - Cancels out different elements - Requires a final verification step Key insight: At any point, the majority element will survive the cancellation process. This is a classic interview problem that tests your understanding of optimization. Have you used Moore’s Algorithm before? #DSA #Java #CodingInterview #Algorithms #SoftwareDevelopment #Programming #Developers
To view or add a comment, sign in
-
🚀 Code 4 – #50LeetCodeChallenge 🧩 Problem: Remove Duplicates from Sorted Array Given a sorted array, remove duplicates in-place so that each unique element appears only once. Return the count of unique elements while maintaining the original order. 💡 Approach: Use the two-pointer technique—one pointer tracks the position of unique elements, while the other scans through the array. When a new unique element is found, place it at the correct position. 📚 Key Takeaway: Two-pointer approach is highly efficient for in-place array modifications, reducing space complexity to O(1) and time complexity to O(n). #LeetCode #Java #Coding #ProblemSolving #Arrays #TwoPointers #Programming
To view or add a comment, sign in
-
-
Understanding Arrays.sort(s, 0, n, (a, b) -> …) When you see this method, here’s what it actually means: s → the array you’re sorting 0 → the starting index (inclusive) n → the ending index (exclusive) (a, b) → a lambda expression defining how two elements are compared 💡 In simple terms: “Sort only the part of the array from index 0 to n-1 using your custom comparator.” This is extremely useful when handling partial datasets, custom numeric ordering, BigDecimal comparisons, or stable sorting rules. #Java #Programming #Developers #TechLearning
To view or add a comment, sign in
-
-
🚀 Code 5– #50LeetCodeChallenge 🧩 Problem: Remove Element Given an array and a value val, remove all occurrences of val in-place and return the count of remaining elements. The order of elements can be changed. 💡 Approach: Use a two-pointer technique—one pointer iterates through the array, while the other keeps track of the position to place elements that are not equal to val. 📚 Key Takeaway: In-place modification with two pointers helps achieve O(n) time complexity and O(1) space, making it efficient for array filtering problems. #LeetCode #Java #Coding #ProblemSolving #Arrays #TwoPointers #Programming
To view or add a comment, sign in
-
-
LeetCode — Problem 5 | Day 12 💡 Problem: Longest Palindromic Substring --- 🧠 Problem: Given a string "s", find the longest substring that is a palindrome. --- 🧠 Approach (Expand Around Center): - Treat each character as a center - Handle two cases: • Odd length → (i, i) • Even length → (i, i+1) - Expand outward while characters match - Track the maximum length substring 👉 Key idea: expand from center instead of checking all substrings --- ⏱ Time Complexity: O(n²) 📦 Space Complexity: O(1) --- 🔍 Insight: A palindrome expands symmetrically from its center --- ⚖️ Edge Cases: - Empty string → return "" - Single character → same character - Even length palindrome (e.g., "bb") - Entire string is a palindrome --- 🔑 Key Learning: - Avoid brute force O(n³) - Efficient pattern: Expand Around Center #LeetCode #DSA #Java #Palindrome #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 15 of 180 — 3Sum Closest ✅ LeetCode 16 — 3Sum Closest First sort the array. Then fix one element and use two pointers for the remaining two — one at left, one at right. For every triplet I calculate the sum and check how far it is from the target: distance = |target - sum| If this distance is less than my current minimum difference, I update my answer. Moving pointers is simple — if sum is greater than target → move right pointer left if sum is less than target → move left pointer right if sum equals target → that's the closest it can get, return immediately The key thing I made sure — keep tracking the minimum difference throughout and update result whenever a closer sum is found. Day 15 done. 165 to go. 🔥 #180DaysDSA #Day15 #LeetCode #Java #DSA #TwoPointers #Sorting #ThreeSum #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 13 of #50DaysOfLeetCode Challenge Solving "Single Number" with the Power of XOR I recently worked on the Single Number problem on LeetCode. The challenge was to find the only non-repeating element in an array where every other element appears twice—all while maintaining Linear Time Complexity and Constant Extra Space. While a HashMap is an obvious choice, it fails the "Constant Space" constraint. The real "magic" solution? Bitwise XOR Why it works: (Identical numbers cancel each other out) (Any number XORed with zero remains unchanged) By XORing every number in the array, all the pairs vanish into zeros, leaving behind only the unique "Single Number." It’s an incredibly elegant and efficient way to handle data! #LeetCode #BitManipulation #Java #Coding #Efficiency #TechLearning
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