🔥 Day 55 of #100DaysOfCode 🔥 🔹 Problem: Add Strings ✨ Approach: Used the power of BigInteger to handle large numeric strings efficiently. Converted both string inputs to BigIntegers, performed direct addition, and converted the sum back to a string — no manual digit handling required! 💡 ⚡ Complexity Analysis: Time Complexity: O(n) — proportional to the length of the longer string Space Complexity: O(1) — constant auxiliary space 📊 Result: ✅ Runtime: 20 ms (Beats 12.14%) ✅ Memory: 44.13 MB (Beats 13.83%) 💡 Key Insight: Sometimes, simplicity wins — leveraging built-in libraries like BigInteger can make your solution both elegant and powerful. 🚀 #100DaysOfCode #LeetCode #Java #BigInteger #StringManipulation #ProblemSolving #DSA #CodingJourney #Programming #CleanCode #LogicBuilding
"Added strings using BigInteger for efficient handling"
More Relevant Posts
-
📌 Day 23/100 – Squares of a Sorted Array (LeetCode 977) 🔹 Problem: Given a sorted integer array (may contain negatives), return a new array of the squares of each number, sorted in non-decreasing order. 🔹 Approach (Two Pointers): Since negative values become positive when squared, the largest values will be at either end of the array. So we: Use left and right pointers Compare squares → place the larger one at the end of result array Move pointers inward and fill result from back to front This avoids sorting again and keeps the solution O(n). 🔹 Time & Space Complexity: ⏱️ Time: O(n) 💾 Space: O(n) (result array) 🔹 Key Learnings: ✅ Two-pointer technique helps avoid extra sorting ✅ Always think about value transformation (like negative → squared) ✅ Filling from the back is a smart trick when maintaining sorted order #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney #TwoPointers #Programming
To view or add a comment, sign in
-
-
✅Day 80 of #100DaysOfLeetCode 1.📌Problem: Set Mismatch You are given an array that represents a set of integers from 1 1 to n n, but due to an error, one number is duplicated and another is missing. The task is to find the duplicated number and the missing number and return them as an array. 2.🟢 Difficulty: Easy 3.📍Topic: Hashing,Array 4.🎯 Goal: Find the number that occurs twice and the number that is missing, then return them in an array. 5.🧠 key idea: Approach 1: Use a HashMap to count occurrences of each number in the input array. Identify the duplicated number by finding the one which appears twice. Compute the total sum expected (n(n+1)/2 n(n+1)/2) and compare with the actual sum (excluding the duplicate). The missing number equals the difference between the expected total and the corrected actual sum. Return the duplicate and missing numbers as the result array. #LeetCode #100DaysOfCode #CodingChallenge #Java #Programming #InterviewPrep #Algorithms #DataStructures #Hashing #ProblemSolving #Array #SoftwareEngineering #TechCareers #LearnToCode #CodeNewbie #DailyCode #ChallengeYourself
To view or add a comment, sign in
-
-
🌟 Day 144 of 150 – LeetCode Challenge 📌 Problem #63: Unique Paths II 🔗 Category: Dynamic Programming 🧩 Problem Brief: ✔ Given an $m \times n$ grid with obstacles (marked as 1) and empty spaces (marked as 0), find the number of unique paths from the top-left to the bottom-right corner. The robot can only move down or right. 🧠 Approach Summary: ➤ This is an extension of the classic Unique Paths problem, solved efficiently using Dynamic Programming with Space Optimization. ➤ A 1D DP array, $\text{dp}$, is used to store the number of unique paths to reach the cells in the current row. The size of $\text{dp}$ is $n$ (the number of columns). ➤ Initialization: * $\text{dp}[0]$ is set to 1, representing one path to the first column's first cell (if it's not an obstacle). ➤ DP Transition: The grid is iterated row by row. For each cell $(i, j)$: * If the cell contains an obstacle ($\text{obstacleGrid}[i][j] == 1$), $\text{dp}[j]$ is set to 0, as no path can go through it. * If the cell is not an obstacle and $j > 0$, the number of paths to reach it is the sum of paths from the cell above it ($\text{dp}[j]$ from the previous row) and the cell to its left ($\text{dp}[j-1]$ from the current row). * If the cell is the first column ($j=0$) and not an obstacle, its path count only depends on the cell above it (which is already stored in $\text{dp}[0]$ before the update). ➤ The final answer is the value at the last column of the DP array, $\text{dp}[n-1]$. ⚡ Result: ✔ Runtime: 0 ms (Beats 100.00%) ✔ Memory: 41.76 MB (Beats 66.83%) #LeetCode #150DaysOfCode #CodingChallenge #Java #DSA #DynamicProgramming #ProblemSolving #CodeEveryday
To view or add a comment, sign in
-
🎯 Day 7 of #365DaysofDSA Today I solved “Maximum Depth of Binary Tree” (LeetCode #104) 🌳 💡 Concepts used: • Recursion • Depth Calculation in Binary Trees ✨ Approach Summary: Used a recursive approach to find the longest path from the root node down to the farthest leaf node. For each node: 1️⃣ Recursively find the maximum depth of its left and right subtrees. 2️⃣ The current node’s depth = max(leftDepth, rightDepth) + 1. This elegant recursive solution divides the problem into smaller subproblems — calculating depth for subtrees and combining the results. 🚀 Key takeaway: Recursive thinking simplifies complex tree problems by leveraging the natural hierarchical structure of binary trees. 🌱 #Day7 #DSA #LeetCode #Java #BinaryTree #Recursion #ProblemSolving #CodingJourney #Programming #LearnByDoing #MaximumDepthOfBinaryTree
To view or add a comment, sign in
-
-
✅Day 62 of #100DaysOfLeetCode 📌Problem: You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. 🟠 Difficulty: Medium 📍Topic: Array, Binary Search 🎯 Goal: Return the single element that appears only once in O(log n) time and O(1) space. 🧠key idea: Approach 1: The problem can be efficiently solved using a modified binary search. The core logic relies on the properties of the sorted array. If we are at an even index, its duplicate pair should be at the next (odd) index. If we are at an odd index, its pair should be at the previous (even) index. By examining the middle element and its neighbor, we can determine if the single, non-duplicated element lies in the left or right half of the array, allowing us to discard one half in each step and achieve a logarithmic time complexity. #100DaysOfCode #LeetCode #CodingChallenge #Java #DataStructures #Algorithms #BinarySearch #ProblemSolving #SoftwareDeveloper #TechJobs #DeveloperLife #CodeNewbie #Programming #LearnToCode #JobSeekers
To view or add a comment, sign in
-
-
💻 Day 69 of #LeetCode100DaysChallenge Solved LeetCode 264: Ugly Number II a dynamic programming problem that improves sequence generation and pointer-based optimization skills. 🧩 Problem: An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the n-th ugly number. 💡 Approach — Dynamic Programming with Three Pointers: 1️⃣ Maintain an array dp where dp[i] stores the i-th ugly number. 2️⃣ Use three pointers p2, p3, and p5 to track multiples of 2, 3, and 5 respectively. 3️⃣ At each step, choose the smallest of dp[p2]*2, dp[p3]*3, and dp[p5]*5 as the next ugly number. 4️⃣ Increment the corresponding pointer(s) to avoid duplicates. 5️⃣ Continue until the nth ugly number is found. ⚙️ Complexity: Time: O(N) — one pass to generate all ugly numbers Space: O(N) — for storing the sequence ✨ Key Takeaways: ✅ Strengthened understanding of pointer-based DP techniques. ✅ Learned how to efficiently generate sorted multiplicative sequences. ✅ Practiced optimization over brute-force factor checking. #LeetCode #100DaysOfCode #Java #DynamicProgramming #TwoPointers #Math #DSA #ProblemSolving #CodingJourney #WomenInTech
To view or add a comment, sign in
-
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
#Day13 2 – Add Two Numbers Solved this classic linked list problem by implementing an efficient algorithm to add two numbers represented as reverse-digit linked lists. 💡 Approach: Used a dummy node to simplify list construction, iterated through both lists while handling different lengths, and maintained a carry value for proper digit summation. The solution elegantly handles cases where lists have different sizes and final carry propagation. #LeetCode #Java #LinkedList #DataStructures #Algorithms #ProblemSolving #Coding #Tech #SoftwareEngineering #DailyCoding #Programming
To view or add a comment, sign in
-
-
🚀 Day 129/160 – Total Decoding Messages | Dynamic Programming Today’s challenge was about decoding numeric messages into alphabets (like 1→A, 2→B...26→Z). Used a DP approach to count all valid decoding ways efficiently. 🧠 Key takeaway: Dynamic Programming shines when a problem’s state depends on previous results — here, each position depends on the previous one and the one before it. #100DaysOfCode #GeeksforGeeks #160DaysOfDSA #DynamicProgramming #ProblemSolving #Java #CodingJourney #LearnByDoing
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