🚀 Day 55 – 100 Days Coding Challenge 📌 Problem: Convert Number to English Words ⚙️ Approach • Break the number into chunks of 3 digits (hundreds) using modulo and division • Process each chunk separately and map it with its corresponding scale (Thousand, Million, Billion) • Use helper arrays for: – Numbers below 20 – Tens (20, 30, …, 90) – Scale values (Thousand, Million, etc.) • For each chunk: – Convert hundreds place – Handle tens and units • Concatenate all parts in the correct order to form the final string 🧠 Logic Used • Mathematical decomposition (splitting number into base-1000 chunks) • String construction using mapping arrays • Handling edge cases like zero and trailing spaces • Modular and reusable helper function for clean conversion 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 55 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #Strings #MathLogic
Convert Number to English Words in Java
More Relevant Posts
-
🚀 Solved LeetCode Problem #58 – Length of Last Word Today I worked on a simple yet insightful string manipulation problem that emphasizes attention to edge cases. 🔍 Problem Insight: Given a string containing words and spaces, the goal is to find the length of the last word, ignoring any trailing spaces. 💡 Approach Used: Instead of using built-in methods like split(), I implemented an optimized approach by: Traversing the string from the end Skipping trailing spaces Counting characters until the next space is encountered This approach avoids extra space usage and improves efficiency. 🧠 Key Learning: Importance of handling edge cases like trailing spaces How reverse traversal can simplify string problems Writing memory-efficient solutions 📈 Complexity: Time: O(n) Space: O(1) ✨ Problems like this help strengthen: String manipulation skills Logical thinking Writing clean and optimized code Consistency is key—one step closer to mastering DSA! 💪 #LeetCode #DSA #StringManipulation #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 14 / 50 – Wild Coding Kickoff Today’s focus was on computing the square root of a number without using built-in functions, and understanding how precision and data types impact the solution. 💡 Key Insight: Integer Division in Java int result = 9 / 2; System.out.println(result); // Output: 4 Java performs integer division when both operands are integers The fractional part is discarded, not rounded To get accurate results in calculations: double result = (double) 9 / 2; // 4.5 ⚡ Approach Used: Newton’s Method Instead of brute force or binary search, I implemented Newton’s Method, which converges faster to the square root. 🧠 Idea: Start with an initial guess Continuously improve it using an average-based formula Stop when the value stabilizes 🔍 Why this works Uses integer-safe division (n / x) to avoid overflow Each iteration brings the guess closer to the actual square root Efficient and avoids floating-point inaccuracies ⏱ Complexity Time: ~ O(log n) (fast convergence) Space: O(1) 🎯 Takeaway Understanding fundamentals like integer division combined with applying efficient algorithms like Newton’s Method leads to both correct and optimized solutions. #Day14 #50DaysOfCode #WildCodingKickoff #Java #DSA #SoftwareEngineering #CodingJourney #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
Day 9/30 – Abstraction and Shortest Path in DAG Day 9 of the challenge focused on learning another important pillar of Object Oriented Programming and solving a graph problem based on shortest paths. Today’s learning was about hiding unnecessary complexity in code and using graph ordering to calculate minimum distances efficiently. MERN / OOP Concepts – Abstraction Today I learned about Abstraction, one of the core pillars of Object-Oriented Programming. What is Abstraction: • Abstraction means hiding internal implementation details and showing only essential functionality • It helps users interact with features without needing to know how everything works internally How it is achieved in Java: • Abstract classes • Interfaces Why it matters: • Reduces complexity • Improves code readability • Makes systems easier to maintain and extend • Focuses on what an object does instead of how it does it Real-world example: • When driving a car, we use steering, brakes, and accelerator • We do not need to understand the engine internals to drive it Key takeaway: • Show only what is necessary, hide the rest DSA – Shortest Path in DAG Today I solved Shortest Path in Directed Acyclic Graph (DAG). Approach: • Build graph using adjacency list with weights • Perform Topological Sort of all nodes • Initialize distance array with infinity • Start source node distance as 0 • Process nodes in topological order • Relax all outgoing edges to update shortest distances Key insight: • Since DAG has no cycles, topological order guarantees that each node is processed after its dependencies • This makes shortest path faster than Dijkstra in DAG cases Why this problem is important: • Combines Topological Sort with shortest path logic • Shows how graph structure can optimize solutions Time Complexity: O(V + E) Space Complexity: O(V + E) Takeaways • Abstraction helps simplify complex systems • Good software design hides unnecessary details • DAG problems often become easier using topological order • Choosing the right graph technique can greatly improve efficiency Day 9 completed. Concepts are getting deeper, and patterns are becoming more natural. #30DaysChallenge #OOP #Abstraction #Java #DSA #Graphs #ShortestPath #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Solved LeetCode Problem #47 – Permutations II Today I tackled a classic backtracking problem that adds an interesting twist—handling duplicate elements while generating permutations. 🔍 Problem Insight: Given an array that may contain duplicates, the goal is to generate all unique permutations without repetition. 💡 Approach Used: I used a Backtracking + Sorting strategy: First, sort the array to bring duplicates together Use a visited[] array to track used elements Apply a smart condition to skip duplicate choices during recursion This ensures that we only generate distinct permutations efficiently. 🧠 Key Learning: Handling duplicates in recursive problems is crucial Sorting helps simplify duplicate detection Backtracking becomes powerful when combined with pruning conditions 📈 Complexity: Time: O(n!) Space: O(n) ✨ This problem strengthened my understanding of: Backtracking techniques Recursion control and pruning Writing optimized solutions for combinatorial problems Consistency in solving such problems is helping me build stronger problem-solving skills every day! 💪 #LeetCode #DSA #Backtracking #Algorithms #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 13/100 – LeetCode Journey 📌 Problem: Rotate Array (LeetCode 189) Today’s problem looked simple at first… but it taught me something deeper about how arrays and math work together. 🔹 Task: Rotate an array to the right by k steps. Example: [1,2,3,4,5,6,7], k = 3 → [5,6,7,1,2,3,4] --- 💡 Key Learning: Instead of shifting elements again and again (which is inefficient), I learned a smarter way using: 👉 "(i + k) % n" This single formula helped me: - Move elements to the correct position - Avoid index out-of-bounds - Understand how modulo (%) creates a circular effect --- 🧠 Biggest takeaway: At first, I struggled with: 👉 Why "3 % 7 = 3" 👉 Why we don’t use decimals in modulo Now it finally makes sense: ✔ Modulo gives the remainder after full division ✔ It helps wrap values within array limits ✔ Arrays can be treated like a circle 🔄 --- 💻 Approach Used: - Extra array to store rotated values - Place each element using "(i + k) % n" - Copy back to original array --- ✨ What I realized: Sometimes the problem isn’t coding… It’s understanding the math behind it. --- #Day13 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 38 of My DSA Journey Today I solved LeetCode 152 – Maximum Product Subarray on LeetCode. 📌 Problem Given an integer array nums, find the contiguous subarray that has the largest product, and return that product. Example: Input: [2,3,-2,4] Output: 6 → subarray [2,3] 🧠 Approach – Dynamic Programming (Tracking Max & Min) This problem is tricky because of negative numbers. Key Idea: • At each index, we maintain: maxProduct → maximum product ending at current index minProduct → minimum product ending at current index 👉 Why min? Because a negative number can turn a small (negative) product into a large positive one. Steps I followed: • Initialize maxProduct, minProduct, and ans with the first element • Traverse the array from left to right • If the current number is negative → swap max and min • Update: maxProduct = max(current, current × maxProduct) minProduct = min(current, current × minProduct) • Update the final answer using maxProduct ⏱ Time Complexity: O(n) — Single pass through the array 📦 Space Complexity: O(1) — No extra space used 💡 Key Learnings ✔ Handling negative numbers in product problems ✔ Using dynamic programming with state tracking ✔ Understanding why tracking both max & min is important This is one of those problems that looks simple but tests deep understanding of edge cases 🚀 Consistency continues — leveling up every day 💪 #100DaysOfCode #DSA #DynamicProgramming #Arrays #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 24 of #100DaysOfCode I stared at this problem for 40 minutes trying every possible target value. Then one insight — borrowed from basic statistics — made it click instantly. 🧩 The Problem: Minimum Operations to Make a Uni-Value Grid (LeetCode 2033 — Medium) Given a 2D grid and a fixed step value x, transform every element to the same value using the minimum number of add/subtract operations. My first instinct? Try every possible target. Loop through everything. Classic overthinking. 😅 💡 The Key Insight — Why the Median? The median minimizes the sum of absolute differences. This is a well-known statistics fact — and it maps perfectly to this problem. Instead of brute-forcing every target, the strategy is simple: → Flatten the 2D grid into a 1D array → Sort it → Pick the middle element (median) as the target → Count total operations using the absolute difference divided by x No guessing. No unnecessary loops. Just math doing the heavy lifting. ⚠️ The Constraint Check Nobody Talks About Before applying any operations — check if all elements share the same remainder when divided by x. If they don't, it's mathematically impossible to make the grid uni-value. Return -1 immediately and save the computation entirely. This "fail fast" mindset is just as important as the algorithm itself. 📈 Complexity Breakdown → Flatten + Sort → O(n log n) → Single pass to count operations → O(n) → Space → O(n) for the flattened array Simple, clean, and efficient. 🧠 What This Problem Reinforced ✅ Greedy thinking with median optimization ✅ Handle impossible cases before computation — fail fast ✅ Transform 2D problems into simpler 1D forms ✅ Let math do the heavy lifting before writing a single loop The best solutions often come from asking: "What does math already know about this?" On to the next challenge 💪 👇 What's a problem where a simple insight saved you from overcomplicating things? Drop it in the comments — would love to learn from your experience! #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #CodingJourney #SoftwareEngineering #Programming
To view or add a comment, sign in
-
-
🚀 Day 54 – 100 Days Coding Challenge 📌 Problem: Three Sum ⚙️ Approach • First, sort the array to make it easier to apply the two-pointer technique • Iterate through the array and fix one element at a time • For each fixed element, use two pointers (left and right) to find pairs whose sum equals the negative of the fixed element • Skip duplicate elements to avoid repeating triplets • Move pointers based on the sum: – If sum == 0 → store the triplet and move both pointers – If sum < 0 → move left pointer forward – If sum > 0 → move right pointer backward 🧠 Logic Used • Sorting + Two Pointer Technique • Handling duplicates efficiently to ensure unique triplets • Reducing time complexity from brute force O(n³) to O(n²) 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 54 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #TwoPointers #ArrayProblems
To view or add a comment, sign in
-
-
🚀 Day 576 of #750DaysOfCode 🚀 🔍 Problem Solved: Minimum Operations to Make a Uni-Value Grid Today’s problem was a perfect blend of math + sorting + greedy thinking 🧠 💡 Key Insight: We can only add or subtract a fixed value x. 👉 So all numbers must have the same remainder when divided by x Otherwise, it’s impossible ❌ 🧠 Approach: 1️⃣ Flatten the grid into a list 2️⃣ Sort the values 3️⃣ Check feasibility: 👉 If (value - firstValue) % x != 0 → return -1 4️⃣ Choose the median as the target value 👉 Why median? It minimizes total operations 5️⃣ Calculate operations: 👉 |value - median| / x 📈 Complexity: Time: O(n log n) (sorting) Space: O(n) ✨ Takeaway: 👉 Always check feasibility first before optimizing 👉 Median is powerful in minimizing absolute differences 👉 Converting 2D → 1D often simplifies the problem Another strong pattern unlocked 🔓 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Greedy #Algorithms #LearningEveryday
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