🚀 LeetCode Day 3: Reverse Integer Today’s challenge was all about reversing the digits of an integer while handling tricky edge cases — especially negative numbers and integer overflow. 🧠 💡 Problem: Given a signed 32-bit integer, reverse its digits. If the reversed integer overflows, return 0. 🧩 Key Takeaways: Extract digits using modulo and division Manage negative numbers gracefully Check for overflow before building the reversed number 💻 Language: Java ✅ Topic: Math / Integer Manipulation Every day is a new step toward mastering problem-solving and improving coding logic. #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #LeetCodeJourney
Reversing integers with Java: LeetCode Day 3
More Relevant Posts
-
🚀 Day 62/100 of #100DaysOfLeetCode Today’s challenge was “Happy Number” (LeetCode Problem 202). The task was to determine whether a given number is a Happy Number — meaning that by repeatedly replacing the number with the sum of the squares of its digits, the process eventually reaches 1. 💡 Key Takeaways: Strengthened understanding of pointer movement logic. Improved implementation skills using mathematical and logical thinking in Java. #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms
To view or add a comment, sign in
-
-
📌 Day 12/100 - Concatenation of Array (LeetCode 1929) 🔹 Problem: Given an integer array nums, create a new array ans such that: ans[i] = nums[i] ans[i + n] = nums[i] where n is the length of nums. In short, we need to concatenate the array with itself to form a new array of size 2n. 🔹 Approach: First, determine the length n of the array. Create a new array newArray of size 2n. Loop through nums once: Assign each element twice — once at position i and once at position i + n. Finally, return the concatenated array. 🔹 Key Learning: Reinforced the concept of array indexing and iteration. Practiced efficient array manipulation in Java. Sometimes, the simplest logic is the cleanest — clarity beats complexity! 💡 Every solved problem adds a layer of confidence and consistency 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing
To view or add a comment, sign in
-
-
Day 89 of #100DaysOfCode Solved Find Numbers with Even Number of Digits in Java 🔢 Approach The goal of this problem was to count how many integers in a given array have an even number of digits. I implemented two methods: findNumbers(int[] nums): This is the main function that iterates through every number in the input array nums. isEvenOrOdd(int n): This helper function takes an integer and determines if its digit count is even or odd. Inside the helper function, I used a while loop to count the digits: I initialized a count to 0. The loop continues as long as $n > 0$. In each iteration, I increment count and then perform integer division by 10 (n = n / 10) to remove the least significant digit. Finally, I return true if the total count of digits is even (count \% 2 == 0). This efficient, digit-by-digit checking approach resulted in a strong performance, beating 98.90% of other submissions. #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Array #ProblemSolving #Optimization
To view or add a comment, sign in
-
-
🧠 Today I revisited a classic problem — removing duplicates from a sorted array in Java. It’s simple at first glance, but understanding why it works step by step really clarifies how two-pointer logic shines in array problems. How it works: j scans the array k marks where the next unique value goes When nums[j] ≠ nums[j-1], copy and move k forward Example: Input → [1,1,2,2,3] Output → k = 3, unique elements = [1,2,3] ✅ Time: O(n) ✅ Space: O(1) #Java #ProblemSolving #Algorithms #Coding #LeetCode
To view or add a comment, sign in
-
-
#Day 3 of the Coding Challenge: The Missing Number! Today, I cracked a classic array problem: Finding the Missing Number in an array containing n distinct numbers from the range [0, n] My final, optimized solution uses the elegant Gauss Summation method with a crucial twist to avoid a common pitfall! # The Problem & The Solution Input: An array nums of length n (e.g., [3, 0, 1]). The numbers are from 0 to n(e.g., 0, 1, 2, 3). Missing Number: 2. Logic: {Missing Number} = {Expected Sum of } 0 { to } n) - ({Actual Sum of Array Elements}) 👨💻 My Optimized Java Code Java class Solution { public int missingNumber(int[] nums) { int n = nums.length; // CRITICAL FIX: Use 'long' for the expected sum calculation // to prevent Integer Overflow for large 'n'. long expectedSum = (long)n * (n + 1) / 2; long actualSum = 0; for(int num : nums){ actualSum += num; } return (int) (expectedSum - actualSum); } } ? Why the long is Key to Optimization While the O(n) summation method is fast, the intermediate value of frac{n(n+1)}{2}can easily exceed Integer.MAX_VALUE if the array is large (around n=65,536). By casting to long, we make the solution robust and production-ready, eliminating the risk of a bug under large constraints! ❓ Quick Poll: Which O(n) method do you prefer for this problem? Gauss Summation (Like above - Math is power!) Bitwise XOR (The clever one that avoids all addition!) Let me know your vote and why in the comments! 👇 #Day3 #CodingChallenge #LeetCode #Java #Programming #Algorithm #DataStructures #TechJobs #SoftwareDevelopment
To view or add a comment, sign in
-
-
#Day_28 Today’s problem was quite an interesting one — “Reach a Target Number” using minimal moves. 💡 Problem Summary: Starting from 0, on each move i, you can go either left or right by i steps. The goal is to find the minimum number of moves required to reach a given target. At first glance, it looked like a simple math problem, but the trick was to notice the parity condition — once the cumulative sum goes beyond the target, the difference (sum - target) must be even to allow flipping directions and still land exactly on target. Here’s the optimized logic I implemented in Java Key Takeaway: Sometimes, problems that look complex are just about observing patterns in numbers rather than brute force. A touch of math can simplify the entire logic! #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #DSA #LearnEveryday #CodingJourney
To view or add a comment, sign in
-
-
💻 LeetCode Challenge – Day 5: String to Integer (atoi) Today's problem was all about converting a string into an integer — seems simple, but the edge cases make it tricky! 🧠 🔹 Problem: Implement the atoi function, which converts a string to a 32-bit signed integer (just like in C/C++). 🔹 Key Learnings: ✅ Handling whitespaces and optional '+' or '-' signs ✅ Managing non-digit characters gracefully ✅ Preventing integer overflow & underflow ✅ Importance of clean parsing logic This problem really improved my understanding of string manipulation and boundary conditions in Java. 🚀 #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringToInteger #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 27 of 100 Days of LeetCode 📘 Problem: Generate Parentheses 💻 Language: Java ✅ Status: Accepted — Runtime: ⚡ 0 ms (Beats 100%) Today’s challenge focused on backtracking, one of the most elegant and powerful problem-solving techniques in DSA. The task was to generate all possible valid combinations of parentheses — a perfect test of recursion and logical constraints 🧩 ✨ Key Learnings: Backtracking is about exploring all possibilities, then undoing choices when needed 🔄 Understanding base cases clearly makes recursion much easier Clean recursive structures lead to elegant and efficient solutions This problem reinforced one important principle — 🧠 “Sometimes, going back is the only way to move forward — both in code and in life.” #Day27 #100DaysOfCode #LeetCode #Java #Backtracking #Recursion #ProblemSolving #CodingJourney #DSA #SoftwareDevelopment #KeepLearning #CodeEveryday
To view or add a comment, sign in
-
-
🔥 LeetCode Day--- 4 | “Median of Two Sorted Arrays” (Hard, Java) Today’s challenge was one of those that really test your logic, patience, and understanding of binary search. This problem wasn’t about just merging two sorted arrays — it was about thinking smarter 🧠. Instead of brute-forcing through both arrays (O(m+n)), I implemented a binary partition approach to achieve O(log(min(m, n))) efficiency 💡 What I learned today: Always choose the smaller array for binary search — it makes the partition logic simpler. Handle boundaries carefully with Integer.MIN_VALUE and Integer.MAX_VALUE. The goal is to find the perfect partition where: Left half ≤ Right half Elements are balanced across both arrays Once that’s done → median can be easily calculated! ✅ Result: Accepted | Runtime: 0 ms 🚀 Hard problem turned into a logic puzzle that was actually fun to solve! 🧩 Concepts Strengthened: Binary Search Partitioning Logic Edge Case Handling Mathematical Thinking #LeetCode #Day4 #Java #BinarySearch #ProblemSolving #CodingChallenge #DataStructures #Algorithms #CodeEveryday #DeveloperJourney #TechLearning #LeetCodeHard #CodingCommunity
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