𝗗𝗮𝘆 𝟭𝟭/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Solved Reverse Integer using Mathematical Digit Extraction. ➤ Approach (O(log₁₀n), O(1) space): • Extract last digit using x % 10 • Remove last digit using x / 10 • Build reversed number using rev = rev * 10 + rem • Before updating, check for overflow using Integer.MAX_VALUE and Integer.MIN_VALUE ➤ Key Insight: The tricky part isn’t reversing — it’s handling overflow without using 64-bit integers. So before multiplying by 10, we ensure the result stays within 32-bit range. #LeetCode #Java #DSA #MathLogic #ProblemSolving #20DaysChallenge #Consistency
Reverse Integer Challenge: LeetCode Solution in Java
More Relevant Posts
-
Day 86/100 – LeetCode Challenge ✅ Problem: #222 Count Complete Tree Nodes Difficulty: Medium Language: Java Approach: Simple DFS Traversal Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Count nodes by traversing entire tree — works for any binary tree. For complete trees, can be optimized further using height properties. Solution Brief: Used global variable lev to track count. Traversed tree in DFS manner (preorder/inorder/postorder). Incremented counter for each non-null node visited. #LeetCode #Day86 #100DaysOfCode #Tree #Java #Algorithm #CodingChallenge #ProblemSolving #CountNodes #MediumProblem #DFS #Traversal #DSA
To view or add a comment, sign in
-
-
Topic: Collection Framework • Collection Framework is used to store and manipulate groups of objects • Core interfaces: List, Set, Queue, Map • Common classes: ArrayList, LinkedList, HashSet, HashMap • Provides built-in methods for sorting, searching, and iteration • Improves data management and code efficiency #Revising #Day28 #Java #CoreJava #Collections #LearningJourney #Consistency
To view or add a comment, sign in
-
Day 40 — Maximum Depth of Binary Tree Solved LeetCode 104: Maximum Depth of Binary Tree. Used recursion: Base case → return 0 if node is null Recursively compute left and right depth Return 1 + max(left, right) Simple problem, but important for understanding tree height, recursion flow, and divide-and-conquer thinking. Building strong tree foundations step by step. #Day40 #LeetCode #BinaryTree #Recursion #DSA #Java #Consistency
To view or add a comment, sign in
-
-
🌳 Day 59/100: Preorder Traversal - Root, Left, Right Day 59. Learning tree traversals. Preorder: Visit root first, then explore. 🎯 📌 Problem: Return preorder traversal of binary tree. 🎯 Recursion: Base case: If node is null, return. Recursive case: Add value, go left, go right. Simple and clean. 📊 Complexity: O(n) time, O(h) space (recursion stack) 🌱 Tree Traversals: Preorder: Root → Left → Right Inorder: Left → Root → Right Postorder: Left → Right → Root Day 59. Traversal patterns building. 🌳 #100DaysOfCode #DSA #LeetCode #Day59 #Java #PreorderTraversal #BinaryTree #TreeTraversal
To view or add a comment, sign in
-
-
🌳 Day 57/100: Insert into BST - Recursion in Trees Day 57. Yesterday searched, today inserted. BST property makes it elegant. 🎯 📌 Problem: Insert a value into a Binary Search Tree. 💡 Recursive Approach: If root is null → Create new node here If val < root → Insert in left subtree If val > root → Insert in right subtree Return root (unchanged) 🎯 The Beauty: Recursion handles the traversal. Each call returns the updated subtree. No manual pointer tracking needed. Example: Insert 4 into tree with root 5: 5 → 4 < 5 → go left 3 → 4 > 3 → go right null → create TreeNode(4) 📊 Complexity: O(h) where h = height 🌱 Learning: Trees + Recursion = Natural fit. Let the call stack do the walking. Day 57. Tree fundamentals building. 🌳 #100DaysOfCode #DSA #LeetCode #Day57 #Java #BST #Recursion #TreeInsertion
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfCode 🌱 Topic: Binary Trees / Recursion ✅ Problem Solved: LeetCode 105 – Construct Binary Tree from Preorder and Inorder Traversal 🛠 Approach: Used preorder to identify the root node. Used inorder to split left and right subtrees. Stored inorder indices in HashMap for fast lookup. Recursively built left and right subtrees using calculated ranges. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) (HashMap) #100DaysOfCode #Day20 #DSA #BinaryTree #Recursion #Java #LeetCode #ProblemSolving #CodingJourney #Consistency #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA Consistency - Day 57 Today I solved the Same Tree problem on LeetCode, which focuses on understanding binary tree structure comparison using recursion. The goal is to determine whether two binary trees are structurally identical and have the same node values. 🧠 Approach: Recursive Tree Traversal To check if two trees are the same: 1️⃣ If both nodes are null, they are identical → return true. 2️⃣ If one node is null and the other is not, trees differ → return false. 3️⃣ If node values are different, trees are not identical. 4️⃣ Recursively check: Left subtree of both trees Right subtree of both trees Both must match for the trees to be identical. ⏱ Complexity Analysis Time Complexity: O(n) Each node is visited once. Space Complexity: O(h) Due to recursion stack (where h is the height of the tree). #DSA #LeetCode #BinaryTree #Java #CodingJourney #Consistency #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 71/100 – LeetCode Challenge ✅ Problem: #1356 Sort Integers by The Number of 1 Bits Difficulty: Easy Language: Java Approach: Custom Comparator with Bit Counting Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Sort integers based on number of set bits (1s in binary representation). If bit counts are equal, sort by natural integer order. Use Integer.bitCount() for efficient population count. Solution Brief: Converted primitive array to Integer[] for custom sorting. Applied Arrays.sort() with comparator: Compare bitCount(a) vs bitCount(b) If equal, compare integers directly using a.compareTo(b) Converted back to primitive array. #LeetCode #Day71 #100DaysOfCode #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #SortByBits #EasyProblem #BitManipulation #Comparator #DSA
To view or add a comment, sign in
-
-
Day 32 – Find Target Indices After Sorting Array Solved this problem by identifying the position of target elements after sorting without actually sorting the array. Key Learnings: Using counting technique instead of full sorting Reducing time complexity from O(n²) to O(n) Logical thinking based on sorted order properties #DSA #Java #Arrays #Optimization #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day 7 of solving Data Structures & Algorithms problems 💻 Today’s problem: Valid Palindrome Approach: • Convert the string to lowercase • Remove non-alphanumeric characters • Compare characters from start and end moving toward the center Great practice for string manipulation and two-pointer thinking. Consistency > Motivation. Every day getting one step closer to becoming a better developer. #DSA #Java #CodingJourney #ProblemSolving #LeetCode
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
Keep it up 👍