Day 50 of #75DaysDSAChallenge Problem: 7. Reverse Integer Difficulty: 🟠 Medium Platform: LeetCode 🧩 Problem Statement Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes it to go outside the signed 32-bit integer range [-2³¹, 2³¹ - 1], return 0. Example: Input: x = 123 Output: 321 💡 Approach 1️⃣ Extract the last digit using x % 10. 2️⃣ Remove the last digit using x / 10. 3️⃣ Add the digit to the reversed number. 4️⃣ Before updating, check for overflow conditions. 5️⃣ Continue until all digits are processed. #LeetCode #Java #DSA #CodingChallenge #75DaysDSAChallenge #ProblemSolving #TechLearning #CodingJourney
Reversing a 32-bit integer with LeetCode
More Relevant Posts
-
🗓 Day 10 / 100 — #100DaysOfLeetCode 🔍 Problem 1437: Check If All 1's Are at Least Length K Places Away Given a binary array nums and an integer k, the goal is to check whether every pair of 1s in the array is separated by at least k zeros. 🧠 My Approach I traversed the array while keeping track of the last index where a 1 appeared. When encountering a new 1: If it’s the first 1, just store its index. Otherwise, check the distance from the previous 1. If the gap is less than k, return false. If no violations are found, return true ⏱ Time Complexity O(n) – Only a single pass through the array. 💾 Space Complexity O(1) – Uses only constant extra space. #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
💡 LeetCode #2824 — Count Pairs Whose Sum Is Less Than Target Today I solved LeetCode Problem 2824: Count Pairs Whose Sum Is Less Than Target 🔢 Problem Summary: Given an integer array nums and a number target, return the number of pairs (i, j) where i < j and nums[i] + nums[j] < target Key Idea: Use the two-pointer technique after sorting the array. Sort the array to make pair checking efficient. Keep one pointer at the start (i) and one at the end (j). If nums[i] + nums[j] is less than target, then all pairs between i and j are valid → add (j - i) to the count. Otherwise, move the right pointer left. This gives an O(n log n) solution due to sorting. #LeetCode #Java #DSA #TwoPointers #Sorting #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 7️⃣7️⃣ of #100DaysOfCode Solved LeetCode Problem #1437 — Check If All 1’s Are at Least K Places Away 🔍✨ 🔧 Concept: Given a binary array, ensure that every 1 is separated by at least K zeros. The solution simply tracks the previous index of 1 and checks the distance. 🧠 Key Idea: Scan the array once When a 1 is found, verify: 👉 currentIndex - previousIndex > k If any pair violates this, return false ⚡ Efficient: Time Complexity: O(n) Space Complexity: O(1) Another clean and efficient logical problem solved. #LeetCode #Java #Arrays #ProblemSolving #DSA #CodingJourney #100DaysOfCode #DeveloperLife #Motivation
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
🗓 Day 6 / 100 – #100DaysOfLeetCode 📘 Problem: 3228. Maximum Number of Operations to Move Ones to the End Difficulty: Medium 💡 Problem Summary: Given a binary string s, you can repeatedly choose an index i where s[i] == '1' and s[i+1] == '0', and move that '1' to the right until it reaches the end of the string or hits another '1'. The goal is to find the maximum number of such operations possible. 🧠 My Approach: Instead of simulating the moves (which would be inefficient), I used a counting strategy: Keep a running count of the number of '1's seen so far (cnt). Whenever a '0' appears after one or more '1's, we can perform cnt operations involving those ones. Sum these up for the final result. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 3/100 - Remove Duplicates from Sorted Array (LeetCode 26) 🔹 Problem: Given a sorted array, remove the duplicates in-place so that each element appears only once and return the new length. You must modify the array without using extra space for another array. 🔹 Approach: I used a simple counting-based approach: Iterate through the array using a single loop. If the current element is the same as the next, skip it. Otherwise, place it at the current count index and increment count. Finally, return count as the number of unique elements. 🔹 Key Learning: Practiced in-place array modification efficiently without extra space. Improved understanding of loop-based filtering logic. Realized that sometimes the simplest linear approach works best! Consistency compounds — each problem adds a new layer of confidence! 🚀#100DaysOfCode #LeetCode #Java #ProblemSolving #Array #DSA #TwoPointers
To view or add a comment, sign in
-
-
🚀Day 99/100 #100DaysOfLeetCode 🔍Problem: Sum of Two Integers✅ 💻Language: Java 💡Approach: Instead of using the ‘+’ or ‘–’ operators, this problem leverages bit manipulation to perform addition. 🔸Use XOR (^) to calculate the sum without carry. 🔸Use AND (&) followed by a left shift (<< 1) to calculate the carry. 🔸Repeat until no carry remains. 📚Key Takeaways: 🔹Reinforced understanding of bitwise operations. 🔹Learned how addition can be simulated using logical operations. 🔹Improved understanding of low-level arithmetic computation. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 40.88 MB (Beats 10.05%) #100DaysOfLeetCode #Java #BitManipulation #CodingChallenge #ProblemSolving #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
DSA Practice – Day 68 🚀 Problem: Subsets II (LeetCode 90) ✨ Brute Force Approach 1. Generate all possible subsets using recursion (like Subsets I). 2. Use a Set or HashSet to store unique subsets and avoid duplicates. 3. Convert the set back to a list before returning the result. Time Complexity: O(2ⁿ × n) (to generate all subsets) Space Complexity: O(2ⁿ × n) (storing all subsets) ✨ Optimal Approach (Backtracking with Duplicate Handling) We use backtracking, but with a twist — handle duplicates smartly. Steps: 1. Sort the array so duplicates come together. 2. Use a loop with a check if(i != ind && nums[i] == nums[i - 1]) continue; to skip duplicates. 3. Recursively generate subsets and backtrack after each recursive call. Time Complexity: O(2ⁿ × n) Space Complexity: O(n) 🌟 Key Idea Sorting + Skipping duplicates ensures we only generate unique subsets efficiently. #Day68 #Backtracking #DSA #Java #LeetCode #Placements
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 72 Rotate String Task: Given two strings s and goal, check if s can become goal after some number of shifts. Example: Input: s = "abcde", goal = "cdeab" → Output: true My Approach: Checked if both strings have the same length. Concatenated the original string: s + s. Verified if goal exists as a substring in the doubled string. Time Complexity: O(N) Space Complexity: O(N) Sometimes, the simplest observation can make a problem effortless like checking if goal exists inside s + s. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #StringManipulation #CodeNewbie #DSA #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
To view or add a comment, sign in
-
Explore related topics
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