Day 28 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Convert Numbers to Words We were given a number. Task was to convert it into words. Example: 123 → One Hundred Twenty Three This problem was more about mapping. And understanding place values. 💻 Approach 🔹️Create mappings for digits 0–9. 🔹️Create mappings for 10–19 (special cases). 🔹️Create mappings for tens like 20, 30, 40... 🔹️Also store place values like hundred and thousand. Then process the number step by step. 🔹️Traverse the number from left to right. 🔹️If more than two digits remain, handle place values. 🔹️If two digits remain and first digit is 1, use teen mapping. 🔹️Otherwise print tens and units separately. Continue until all digits are processed. 📊 Complexity Analysis Time Complexity: O(n) Each digit is processed once. Space Complexity: O(1) Only fixed mapping arrays are used. 📚 What I learned today: ▫️This problem is essentially a lookup + formatting problem using constant mapping tables. ▫️Handling special ranges (10–19) separately avoids incorrect word formation. ▫️Breaking the number into place-value segments (hundreds, tens, units) simplifies logic. ▫️Designing clean mapping structures is important for problems involving symbolic representation. Day 28 completed. Learning different problem patterns every day 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
Converting Numbers to Words in 50 Days of Code Challenge
More Relevant Posts
-
Day 38 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Print Bracket Number We were given a string str. It contains brackets. Task was to assign a number to each bracket. Each pair gets the same number. Based on order of opening. Let’s understand it simply. ◾️Imagine you are assigning IDs to tasks. ◾️Every time a new task starts, you give it a new ID. ◾️When that task ends, it keeps the same ID. ◾️Multiple tasks can be nested. ◾️But each one has its own number. That’s exactly how brackets behave. 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Initialize a counter = 0. 🔹️Traverse the string. 🔹️If opening bracket: ▪️Increase counter ▪️Push it into stack ▪️Print the counter 🔹️If closing bracket: ▪️Take top value from stack ▪️Print it ▪️Pop from stack Each pair gets same number. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack helps in tracking nested structures. ▫️Assigning IDs during traversal simplifies pairing logic. ▫️LIFO nature perfectly matches bracket problems. ▫️Nested patterns are easier with stack-based thinking. Day 38 completed. Stack understanding getting stronger 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 136 – LeetCode 150 Days Challenge Today’s problem was about generating Combinations using Backtracking. 🧩 Problem Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n]. Example: Input: n = 4, k = 2 Output: [1,2] [1,3] [1,4] [2,3] [2,4] [3,4] 💡 Key Idea This is a classic Backtracking problem. Instead of generating all subsets and filtering them, we build combinations step by step. Steps: 1️⃣ Start from a number 2️⃣ Add it to the current combination 3️⃣ Recursively choose the next numbers 4️⃣ When the combination size becomes k, store it 5️⃣ Backtrack and try other possibilities Backtracking helps us explore all valid possibilities efficiently. ⚙️ Approach Maintain a temporary vector t to store the current combination. Start iterating from start to n. Add the number to the current combination. Recursively call the function for the next numbers. Remove the number (backtrack) to explore other choices. ⏱ Complexity Time Complexity: O(C(n, k) × k) Space Complexity: O(k) (recursion stack) 📚 What I Learned Today ✔️ How Backtracking explores combinations efficiently ✔️ Importance of adding and removing elements (push/pop) during recursion ✔️ How recursion trees help visualize combination generation 🔥 Consistency is the key to mastering DSA. #LeetCode #DSA #Backtracking #150DaysOfCode #CodingChallenge #Cpp #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 5 of 100 Days of LeetCode – Improving Problem-Solving Skills Problem Solved: Move Zeroes Today’s problem focused on rearranging an array such that all zeroes are moved to the end while maintaining the relative order of the non-zero elements. 🔍 Approach: Instead of creating a new array or performing multiple shifts, the optimized solution uses a two-pointer technique. One pointer tracks the position where the next non-zero element should be placed, while the other pointer traverses the array. Whenever a non-zero element is encountered, it is swapped to the correct position. This ensures all non-zero elements remain in order while pushing zeroes toward the end efficiently. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) 💡 Key Takeaways: • Learned how the two-pointer technique simplifies array manipulation • Importance of in-place operations to reduce extra space usage • Strengthening understanding of efficient array traversal Each problem solved helps build stronger algorithmic thinking and coding discipline. #Day5 #100DaysOfLeetCode #LeetCode #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 40 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Mean of Array using Recursion We were given an array. Task was to find the mean (average). But using recursion. This one was a bit different. Not direct sum. It builds from smaller parts. 💻 Approach (Using Recursion) 🔹️Define a function mean(arr, n). 🔹️Base case → if n == 1, return arr[0]. 🔹️Recursively find mean of first n-1 elements. 🔹️Convert that mean back to sum → mean × (n-1). 🔹️Add current element arr[n-1]. 🔹️Divide total by n. Formula used: mean(arr, n) = (mean(arr, n-1) × (n-1) + arr[n-1]) / n This builds the answer step by step. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can be used to build aggregate values step by step. ▫️We can convert mean back to sum using (mean × count). ▫️Understanding recurrence relation is important. ▫️Not all recursive problems are about printing or traversal. Day 40 completed. Getting deeper into recursion concepts 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 43 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Factorial of a Number We were given an integer n. Task was to find n! Factorial means: n! = n × (n-1) × (n-2) … × 1 Example: 5! = 5 × 4 × 3 × 2 × 1 = 120 💻 Iterative Approach 🔹️Initialize result = 1. 🔹️Run a loop from 1 to n. 🔹️Multiply each number with result. 🔹️Return final result. Simple loop. Easy to understand. Time Complexity: O(n) Space Complexity: O(1) 💻 Recursive Approach 🔹️Base case: ▪️If n == 0 or n == 1 → return 1 🔹️Recursive case: ▪️Return n × factorial(n-1) Breaks problem into smaller parts. Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion is based on defining smaller subproblems. ▫️Base case is necessary to stop recursion. ▫️Iterative approach is more space efficient. ▫️Same problem can be solved in multiple ways. Day 43 completed. Strengthening recursion vs iteration concepts 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 70 of #100DaysOfCode 📌 LeetCode Q3: 3Sum 💡 Problem: Find all unique triplets in the array which gives the sum of 0. 🧠 Approach I Used: - First, sorted the array - Fixed one element - Applied two-pointer technique for the remaining part - Skipped duplicates to avoid repeated triplets ⚡ Key Insight: Instead of brute force O(n³), using sorting + two pointers reduces it to O(n²) ❗ Edge Cases Handled: - Duplicate values - No valid triplets - Negative + positive mix ⏱ Complexity: - Time: O(n²) - Space: O(1) (excluding result) 🔥 Takeaway: Two-pointer + sorting = deadly combo for array problems 💯 💬 Open to feedback & better approaches! #Day70 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 48 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Next Greater Element We were given an array. For each element, we had to find the next greater element on the right side. If none exists → return -1. Example: [4, 5, 2, 10] → [5, 10, 10, -1] 💻 Brute Force Approach 🔹️For each element, check all elements on the right. 🔹️Find the first greater element. 🔹️If found → store it. 🔹️Else → store -1. Time Complexity: O(n²) Space Complexity: O(1) Works. But slow. 💻 Optimal Approach (Using Stack) 🔹️Traverse from right to left. 🔹️Use a stack to store elements. 🔹️For each element: ▪️Pop smaller elements from stack ▪️Top of stack = next greater element ▪️If stack empty → answer is -1 🔹️Push current element into stack Efficient. Single pass. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Monotonic stack helps in nearest greater problems. ▫️Traversing from right simplifies logic. ▫️Popping smaller elements keeps stack useful. ▫️Stack stores only potential answers. Day 48 completed. Stack patterns getting stronger 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Solved an interesting algorithm problem today! | Day 2 of 100 Days of LeetCode Problem: Best Time to Buy and Sell Stock The challenge was to determine the maximum profit from a single buy and sell transaction given an array of daily stock prices. Approach: A brute-force solution would compare every pair of days, resulting in O(n²) time complexity. However, the optimized approach involves tracking the minimum stock price encountered so far while traversing the array. At each step, we calculate the potential profit by subtracting the minimum price from the current price, updating the maximum profit whenever a better opportunity appears. This allows the problem to be solved efficiently in O(n) time using a single pass. Key Learnings from Today’s Problem: • The importance of choosing the right approach instead of brute force • How a simple observation can significantly improve algorithm efficiency • Strengthening understanding of arrays and greedy strategies Consistent practice like this helps build stronger problem-solving skills, logical thinking, and coding efficiency. Looking forward to learning something new with every problem solved. #Day2 #100DaysOfLeetCode #LeetCode #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 66 of #100DaysOfCode Today, I solved LeetCode 73 – Set Matrix Zeroes, a classic problem that tests in-place matrix manipulation and optimization techniques. 💡 Problem Overview: Given a matrix, if any cell contains 0, its entire row and column must be set to 0. The challenge is to perform this efficiently without using excessive extra space. 🧠 Approach: To solve this optimally, I focused on: ✔️ Using the first row and first column as markers ✔️ Tracking whether the first row/column initially contained zero ✔️ Updating the matrix in-place based on these markers This avoids using additional space and achieves optimal performance. ⚡ Key Takeaways: In-place algorithms help reduce space complexity Using matrix itself as storage is a powerful optimization trick Handling edge cases (first row/column) is critical 📊 Complexity Analysis: Time Complexity: O(n × m) Space Complexity: O(1) Improving problem-solving skills one day at a time 🚀 #LeetCode #100DaysOfCode #DSA #Matrix #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
Day 78/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 141 – Linked List Cycle (Easy) 🧠 Approach: Use Floyd’s Cycle Detection (Tortoise & Hare). Move one pointer one step and another two steps. If they meet, a cycle exists. 💻 Solution: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: slow = head fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return True return False ⏱ Time | Space: O(n) | O(1) 📌 Key Takeaway: Using two pointers at different speeds is an efficient way to detect cycles without extra space. #leetcode #dsa #development #problemSolving #CodingChallenge
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