🚀 Day 42 of #100DaysOfCode – Striver’s DSA Sheet 🚀 ✅ Problem Covered Today: Palindrome Number 🧩 (LeetCode #9) 💡 Lesson of the Day (Approach-Focused): 🔹 Problem Statement: Given an integer x, return true if x is a palindrome, and false otherwise. A palindrome number reads the same forward and backward. 🧩 Example: Input → x = 121 Output → true Explanation → 121 reads the same both ways. 🧠 Approach: Mathematical Reversal (Without String Conversion) 1️⃣ If x is negative → directly return false. 2️⃣ Store the original number in a variable. 3️⃣ Reverse the number digit by digit using modulus (% 10) and division (/ 10). 4️⃣ Compare the reversed number with the original. If equal → it’s a palindrome. Otherwise → not a palindrome. 🧮 Time Complexity: O(log₁₀n) → number of digits 💾 Space Complexity: O(1) ✨ Key Idea: By using pure arithmetic operations, we avoid extra memory and string manipulation, making the solution efficient and elegant. It’s a great warm-up problem for digit-based logic and reverse-integer type challenges. 💭 Learning: Today’s problem strengthened my control over mathematical operations and logical flow — helping me think beyond string-based shortcuts. #100DaysOfCode #DSA #StriversSheet #LeetCode #PalindromeNumber #ProblemSolving #Java #CodingJourney #LogicBuilding #Consistency #Learning
"Day 42 of #100DaysOfCode: Palindrome Number Solution"
More Relevant Posts
-
🔥 Day 116 of My DSA Challenge – Move Zeroes 🔷 Problem : 283. Move Zeroes 🔷 Goal : Move all 0s to the end of the array while maintaining the relative order of non-zero elements. Must be done in-place without using extra space. 🔷 Key Insight : This problem focuses on in-place array manipulation and pointer logic. We need to keep all non-zero elements in front and shift all zeros toward the end — but without disturbing their relative order. A simple and efficient solution is to use the two-pointer approach: One pointer (idx) scans through the array. Another pointer (k) keeps track of where the next non-zero should be placed. 🔷 Approach : 1️⃣ Initialize pointer k = 0 2️⃣ Traverse the array with index idx 3️⃣ If nums[idx] != 0, assign nums[k] = nums[idx] If k != idx, set nums[idx] = 0 to push zero backward Increment k 4️⃣ The array is now rearranged in-place Time Complexity: O(n) Space Complexity: O(1) This problem strengthens array manipulation and in-place optimization skills. Use pointers wisely — move only what’s needed, keep it clean, keep it fast. This logic is useful for : ✅ Partitioning problems ✅ Rearranging arrays ✅ In-place sorting optimizations Another small but meaningful win — one step closer to mastering the art of clean, efficient code 🚀 #Day116 #DSA #100DaysOfCode #LeetCode #TwoPointers #Arrays #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #EngineerMindset #LogicBuilding #GrowEveryday
To view or add a comment, sign in
-
-
🚀 DSA Challenge – Day 82 Problem: Minimum Good Integer After Card Flips 🃏✨ This problem was a clever mix of logic and set manipulation — focusing on eliminating impossible candidates and finding the smallest valid result through reasoning. 🧠 Problem Summary: You are given two arrays, fronts and backs, representing cards on a table. Each card shows a number on the front and another on the back. ✅ You can flip any number of cards. ✅ A number is good if it appears on the back of at least one card and not on the front of any card. ✅ The goal is to find the smallest possible good number, or 0 if no such number exists. ⚙️ My Approach: 1️⃣ Identify all numbers that appear on both sides of the same card — these can never be good. 2️⃣ Iterate through all front and back numbers, ignoring the common ones. 3️⃣ Keep track of the smallest number that satisfies the condition. 4️⃣ If no valid number exists, return 0. 📈 Complexity: Time: O(n) → Single pass through all cards. Space: O(n) → For storing common values in a set. ✨ Key Takeaway: Sometimes, solving problems efficiently is about identifying what’s impossible first — and simplifying the search space by eliminating it. 🧩 🔖 #DSA #100DaysOfCode #LeetCode #ProblemSolving #SetTheory #LogicBuilding #CodingChallenge #Python #InterviewPrep #TechCommunity #EfficientCode #LearningEveryday #CodeNewbie #Developers #SoftwareEngineering
To view or add a comment, sign in
-
-
✨ Day 101 of My DSA Challenge – Magnetic Force Between Two Balls 🔷 Problem: 1552. Magnetic Force Between Two Balls 🔷 Goal: Place m balls into sorted basket positions such that the minimum magnetic force (i.e., minimum distance between any two balls) is as large as possible. 🔷 Key Insight: This is another brilliant Binary Search on the Answer problem. Instead of directly computing distances, we binary search for the maximum possible minimum distance that still allows placing all balls. Here’s how the logic works: 1️⃣ Sort all basket positions. 2️⃣ Use binary search on the range of possible distances (0 to max(position) - min(position)). 3️⃣ For each middle distance mid, check feasibility using a greedy approach — place balls while maintaining at least mid distance apart. 4️⃣ If it’s possible → try a larger distance. If not → reduce the distance. 🔷 My Java Approach: Implemented a helper function isPossible() to check if we can place all balls for a given minimum distance. Used Binary Search to maximize that minimum distance. 🔷 Complexity: Time → O(n × log(maxDist)) Space → O(1) This problem beautifully blends sorting, binary search, and greedy placement — showing how abstract concepts like “searching on the answer” translate into real algorithmic reasoning. Every new day strengthens my foundation in Binary Search patterns, sharpening both logic and implementation clarity. 🚀 #Day101 #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #BinarySearch #GreedyAlgorithm #CodingChallenge #Programming #SoftwareEngineering #Algorithms #DataStructures #TechJourney #LearnToCode #CodeEveryday #EngineerMindset #DeveloperJourney #GrowthMindset #KeepLearning #ApnaCollege #AlphaBatch #ShraddhaKhapra
To view or add a comment, sign in
-
-
🔹 DSA Daily | Check for Balanced Parentheses (C++) Balanced parentheses problems are a classic way to test your understanding of **stacks** and **logical thinking**. Today, I solved one such problem — checking if a string of parentheses, braces, and brackets is balanced. 💡 Problem Statement: Given a string containing '(', ')', '{', '}', '[' and ']', determine if the string is **balanced**. A string is balanced if every opening bracket has a corresponding closing bracket in the correct order. Approach: I used a **stack** to keep track of opening brackets. - Push every opening bracket onto the stack. - For closing brackets, check if the top of the stack has the matching opening bracket. - If it does, pop it; otherwise, the string is unbalanced. - At the end, if the stack is empty, the string is balanced. Time Complexity: O(n) — traversing the string once Space Complexity: O(n) — for the stack This problem highlights how **stacks make bracket-matching elegant and efficient**. 🚀 #DSA #CPlusPlus #Coding #ProblemSolving #Stack #BalancedParentheses #CodeEveryday #GeeksforGeeks #LeetCode #ProgrammingJourney #DataStructures #Algorithms #InterviewPrep #CodingCommunity #LogicBuilding #EfficientCode #LearnToCode #TechJourney
To view or add a comment, sign in
-
-
🔥 Day 108 of My DSA Challenge – Merge Sorted Array 🔷 Problem : 88. Merge Sorted Array 🔷 Goal : Merge two sorted arrays into one sorted array in-place inside nums1. The tricky part? nums1 already has extra space at the end — and we need to fill it without using extra arrays. 🔷 Key Insight : Use the two-pointer technique starting from the end — this avoids overwriting values in nums1. Pointer p1 → end of valid elements in nums1 Pointer p2 → end of nums2 Pointer idx → last index in final merged array Place the largest element first by comparing from the end. 🔷 Approach : 1️⃣ Start from the last elements of both arrays 2️⃣ Compare and place the greater one at the end 3️⃣ Move pointers backwards 4️⃣ If nums2 still has elements, copy them This gives us O(m + n) time and O(1) extra space ✅ Sometimes the most elegant solutions are not about building new structures but smartly reusing what you already have. Two-pointer technique continues to be a powerful tool in array problems 💪 #Day108 #100DaysOfCode #LeetCode #DSA #Java #TwoPointers #Arrays #CodingChallenge #Algorithm #InPlaceAlgorithms #ProblemSolving #Programming #SoftwareEngineering #TechJourney #DeveloperJourney #CodeEveryday #LearnDSA #GrowthMindset #EngineerMindset #LogicBuilding
To view or add a comment, sign in
-
-
Day 55 of My DSA Challenge Problem: Count the number of triplets in an array that can form a valid triangle. Concept Recap: For any three sides to form a triangle, the sum of any two sides must be greater than the third side. Optimized Approach: Instead of checking every triplet (which takes O(N³)), I sorted the array and used a two-pointer technique to bring it down to O(N²): Sort the array. Fix the largest side (arr[k]) and use two pointers (i, j) to find pairs where arr[i] + arr[j] > arr[k]. If the condition holds, all elements between i and j can form valid triangles. Count and move pointers accordingly. Time Complexity: O(N²) Space Complexity: O(1) Takeaway: Sorting combined with the two-pointer approach often transforms brute-force solutions into elegant and efficient ones. #Day55 #DSAChallenge #TwoPointerTechnique #Sorting #Optimization #Java #ProblemSolving #DataStructures #Algorithms #CodingChallenge #GeeksforGeeks #LeetCode #100DaysOfCode #ProgrammersJourney #TechLearning
To view or add a comment, sign in
-
-
🔥 Day 113 of My DSA Challenge – Word Search 🔷 Problem : 79. Word Search 🔷 Goal : Check if a given word exists in a 2D grid by connecting sequentially adjacent letters (horizontally or vertically). Same cell cannot be used more than once. 🔷 Key Insight : This is a DFS + backtracking problem. Start from every cell matching the first character. Explore all 4 directions recursively. Track visited cells to avoid reusing letters. Backtrack when a path fails. This teaches how to explore grids efficiently using recursion and state tracking. 🔷 Approach : 1️⃣ Iterate over all cells to find starting points 2️⃣ DFS recursively for adjacent letters 3️⃣ Use a visited matrix to avoid reusing cells 4️⃣ Backtrack if the path does not lead to the word Time Complexity: O(m × n × 4^k) where k = length of word Space Complexity: O(m × n) for visited + recursion stack Word Search reinforces grid DFS + backtracking patterns. Explore all possibilities, track state carefully, backtrack on failure. This pattern is useful for : ✅ Maze solving ✅ Island counting problems ✅ Pathfinding & puzzle problems Every day, a new pattern becomes familiar. Step by step, the mind gets sharper. 🚀 #Day113 #DSA #100DaysOfCode #DFS #Backtracking #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney
To view or add a comment, sign in
-
-
Day 4 of DSA Practice - Advanced Array Patterns After revisiting some fundamentals, I dove into two of the most classic yet tricky array problems, ones that truly test logical depth and optimization thinking 1️⃣ Trapping Rain Water → Used two pointers (left & right) and tracked the maximum walls on both sides (maxLeft, maxRight). → The trapped water at any point = min(maxLeft, maxRight) - height[i]. 💡 Trick: Instead of precomputing leftMax and rightMax arrays, I used a two-pointer approach for O(n) time and O(1) space, clean and efficient. 2️⃣ Sliding Window Maximum → Applied a monotonic deque to maintain indices of useful elements in the current window. → Always keep the deque in decreasing order of values so the front element is the maximum. 💡 Trick: Remove out-of-window indices from the front and smaller elements from the back, brilliant O(n) solution without recomputation. ✨ Takeaway: These two problems reminded me how optimization is all about perspective. Sometimes, a clever data structure or pointer movement can replace multiple loops. #DSA #ProblemSolving #Java #WomenInTech #LearningEveryday #CodingJourney #Arrays #Optimization
To view or add a comment, sign in
-
#Day 1: Remove Duplicates from Sorted Array . "Marked Day 1 of my DSA journey with an O(n)time solution to the 'Remove Duplicates from Sorted Array' problem (LeetCode #26)." # Algorithm Choice: The Two-Pointers Technique Since the array is sorted, the most efficient solution is the Two-Pointers approach, which operates in-place. Pointers: A slow pointer (i) marks the position for the next unique element, and a fast pointer (j) iterates through the array to find new values. Logic: If nums[j] is different from nums[i], we found a unique value! We increment i and write nums[j] to nums[i]. We skip duplicates by simply advancing j. #CODE: class Solution { public int removeDuplicates(int[] nums) { int i = 0; for (int j = 1; j < nums.length; j++) { if (nums[j] != nums[i]) { i++; nums[i] = nums[j];} } return i + 1; }} #Time Complexity:O(n)-Optimal linear time, as we only traverse the array #.Space Complexity-O(1)-Solved in-place using constant extra memory. Solving this with an optimal O(n) time and O(1) space solution is a great start! What's your favorite O(1) space array trick? Share it below! 👇 #DSA #DailyChallenge #LeetCode #Java #Coding #TwoPointers #SoftwareEngineering #InterviewPrep
To view or add a comment, sign in
-
-
✅ Day 58 of LeetCode Medium/Hard Edition Today’s challenge was “2 Keys Keyboard” — a deceptively simple yet deeply insightful problem involving recursion, dynamic programming, and mathematical optimization 🧮✂️📄 📦 Problem: We start with a single character 'A' on a notepad. In each operation, you can perform one of two actions: 1️⃣ Copy All — copy the entire current content of the screen. 2️⃣ Paste — paste what was last copied. Given an integer n, the goal is to determine the minimum number of steps needed to get exactly n 'A's on the screen. 🔗 Problem Link: https://lnkd.in/gKsJ4rw7 ✅ My Submission: https://lnkd.in/giXAhSUX 💡 Thought Process: At every point, you have two options — copy the current string or paste the last copied one. The challenge lies in deciding when to copy, since a well-timed copy can exponentially accelerate progress. This naturally forms a state-space recursion where each state depends on: the current length (len), and the last copied size (last). Using memoization, we store results for (len, last) pairs to avoid recomputation. An interesting mathematical observation: The problem can also be solved by breaking n into its prime factors, since each factor represents an optimal copy-paste cycle. ⚙️ Complexity: ⏱ Time: ~O(n²) (due to recursive branching) 💾 Space: O(n²) for memoization #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Recursion #ProblemSolving #Java
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