Day 39 of #100DaysOfLeetCode 💻✅ Solved #258. Add Digits problem in Java. Approach: • Used a loop to repeatedly add all digits of the number • Extracted each digit using modulus (%) and divided the number by 10 • Stored the digit sum and repeated the process until the result became a single digit • Returned the final single digit as the answer Performance: ✓ Runtime: 1 ms (Beats 97.92% submissions) ✓ Memory: 42.52 MB Key Learning: ✓ Practiced digit extraction using modulus and division ✓ Understood how to repeatedly reduce a number to a single digit ✓ Strengthened problem-solving using loops and basic number manipulation Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
Java Solution for LeetCode #258 Add Digits Problem
More Relevant Posts
-
Day 62 of #100DaysOfLeetCode 💻✅ Solved #219. Contains Duplicate II problem in Java. Approach: • Used two nested loops to compare elements within range k • For each element, checked next k elements • If any duplicate is found within distance k, returned true • If no such pair exists, returned false Key Learning: ✓ Practiced checking duplicates within a given range ✓ Strengthened understanding of array traversal with conditions ✓ Learned the importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 34/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 709. To Lower Case Used ASCII manipulation to convert uppercase letters to lowercase by adding 32, without using built-in functions. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) Strengthening understanding of character encoding and string manipulation basics. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 63 of #100DaysOfLeetCode 💻✅ Solved #2085. Count Common Words With One Occurrence problem in Java. Approach: • Iterated through each word in the first array • Avoided duplicate checks by ensuring each word is processed only once • Counted occurrences of the current word in both arrays • If the word appears exactly once in both arrays, incremented the result • Returned the final count Performance: ✓ Runtime: 88 ms (Beats 7.45% submissions) ✓ Memory: 46.06 MB (Beats 93.07% submissions) Key Learning: ✓ Practiced handling duplicates and frequency counting ✓ Improved understanding of string comparison in arrays ✓ Learned importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 30/100 - LEETCODE Challenge ✅ Problem : Ransom Note Solved the Ransom Note problem using Java! I implemented an efficient approach using a frequency array to count the occurrences of each character in the magazine string and then reduced the count while checking the ransomNote string. If any character count becomes negative, it means the magazine does not have enough letters to construct the ransom note. This solution runs in O(n + m) time complexity with constant space (26 letters), making it highly optimized. ✅ Runtime: 1 ms (Beats 99.85%) ✅ Memory: 46.31 MB Great practice for understanding character frequency, arrays, and greedy checking techniques in string problems. #100DaysOfCode #java #Coding #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 92 – #100DaysOfCode Qn. Combination Sum III Today I worked on the Combination Sum III problem using recursion and backtracking in Java. 🔹 Problem Summary: Find all possible combinations of k numbers that add up to n, using numbers 1–9 only once. 🔹 My Approach: Used recursion to explore all possible number combinations. Maintained a running sum and a temporary list. When the sum equals n and the list size equals k, the combination is added to the result. Used a HashSet to avoid duplicate combinations. 🔹 Key Learning: This problem helped me strengthen my understanding of: Backtracking Recursive decision trees Managing state during recursion (adding/removing elements) 📌 Next Goal: Optimize the solution further by avoiding the HashSet and pruning unnecessary recursive calls. #Day92 #LeetCode #DSA #Java #Recursion #Backtracking #CodingJourney
To view or add a comment, sign in
-
-
Day 67 of #100DaysOfLeetCode 💻✅ Solved #91. Decode Ways problem in Java. Approach: • Checked if the input string is empty or starts with '0' • Initialized a DP array to store number of ways to decode up to each index • Used dp[i] = dp[i-1] if single digit is valid (1–9) • Added dp[i-2] if two-digit number is valid (10–26) • Returned dp[n] as the total number of decoding ways Performance: ✓ Runtime: 1 ms (Beats 99.90%) ✓ Memory: 41.5 MB (Beats 55%) Key Learning: ✓ Practiced dynamic programming with strings ✓ Strengthened understanding of single vs double digit constraints ✓ Reinforced how to build DP solutions incrementally Learning one problem every single day 🚀 #Java #LeetCode #DSA #DynamicProgramming #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 88 - LeetCode Journey Solved LeetCode 24: Swap Nodes in Pairs in Java ✅ This problem is a great exercise in pointer manipulation in linked lists. Instead of changing values, I swapped the actual nodes by carefully adjusting the next pointers. Using a dummy node made the process much cleaner and helped handle edge cases smoothly. Step by step, I swapped pairs while moving forward in the list. Key takeaways: • Deep understanding of pointer manipulation • Importance of dummy node in linked list problems • Clean handling of edge cases • Iterative approach for swapping nodes ✅ All test cases passed ⚡ Efficient O(n) time and O(1) space Linked list problems like this really sharpen your fundamentals 🔥 #LeetCode #DSA #Java #LinkedList #Pointers #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 41 of #100DaysOfLeetCode 💻✅ Solved #242. Valid Anagram problem in Java. Approach: • Converted both strings to lowercase to ensure case-insensitive comparison • Converted the strings into character arrays • Sorted both arrays using Arrays.sort() • Compared the sorted arrays using Arrays.equals() • If both arrays match, the strings are anagrams Performance: ✓ Runtime: 11 ms (Beats 28.32% submissions) ✓ Memory: 46.83 MB (Beats 8.28% submissions) Key Learning: ✓ Practiced string manipulation and character array handling in Java ✓ Understood how sorting helps in comparing character frequencies ✓ Strengthened problem-solving skills for string-based problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 44 of #100DaysOfLeetCode 💻✅ Solved Very Simple #169. Majority Element problem in Java. Approach: • Sorted the given array using Arrays.sort() • Observed that the majority element appears more than n/2 times • After sorting, the majority element will always be present at index n/2 • Returned the element at nums[n/2] Performance: ✓ Runtime: 7 ms (Beats 42.86% submissions) ✓ Memory: 55.96 MB (Beats 16.21% submissions) Key Learning: ✓ Understood how sorting can help identify the majority element ✓ Learned the property that the majority element always occupies the middle position after sorting ✓ Practiced array manipulation and problem solving in Java Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 40 of #100DaysOfLeetCode 💻✅ Solved #112. Path Sum problem in Java. Approach: • Used recursion to traverse the binary tree from root to leaf • Subtracted the current node value from the targetSum at each step • Checked whether the current node is a leaf node (no left and right children) • If the remaining sum becomes 0 at the leaf node, returned true • Otherwise continued checking the left and right subtrees recursively Performance: ✓ Runtime: 1 ms (Beats 6.06% submissions) ✓ Memory: 45.18 MB (Beats 27.94% submissions) Key Learning: ✓ Practiced root-to-leaf traversal in binary trees ✓ Learned how to track the remaining sum during recursion ✓ Improved understanding of recursive tree problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
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