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
Mean of Array using Recursion in 50 Days of Code Challenge
More Relevant Posts
-
Day 46 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Geometric Sum using Recursion We were given an integer n. Task was to find the sum: 1 + 1/3 + 1/3² + ... + 1/3ⁿ Using recursion. 💻 Approach 🔹️Define a recursive function sum(n). 🔹️Base case: ▪️If n == 0 → return 1 🔹️Recursive case: ▪️Return sum(n-1) + 1/(3ⁿ) Each call adds one term. And moves toward smaller n. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can be used for summation of series. ▫️Each recursive call adds one term to the result. ▫️Understanding base case is important to stop recursion. ▫️Power calculations are common in series problems. Day 46 completed. Getting more comfortable with recursive formulas 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 6 — Remove Duplicates from Sorted Array Continuing my journey of improving problem-solving skills with consistency and discipline — one problem every day. Today’s problem focused on optimizing space and modifying arrays efficiently in-place. 🧩 Problem Solved: • Remove Duplicates from Sorted Array (LeetCode #26) 📚 Topic: Two Pointers + Array Manipulation 💡 Key Insight: Since the array is already sorted, duplicates are adjacent — making it possible to remove them using a two-pointer approach without extra space. ⚡ Approach: • Initialize a pointer i to track unique elements • Traverse array using another pointer j • Compare nums[j] with nums[i] • If different → move i forward and update value • Return i + 1 as the count of unique elements 🎯 Takeaway: Understanding problem constraints (like sorted input) can lead to more efficient and elegant solutions. ⏱ Complexity: • Time → O(n) • Space → O(1) 💻 Example: Input → [1, 1, 2] Output → 2 (Array becomes [1, 2, _]) Input → [0,0,1,1,1,2,2,3,3,4] Output → 5 (Array becomes [0,1,2,3,4,_,_,_,_,_]) Efficiency isn’t always about doing more — sometimes it’s about doing less, smarter 🚀 #ProblemSolving #LeetCode #TwoPointers #CodingJourney #100DaysOfCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 16 of 100 Days LeetCode Challenge Problem: Get Biggest Three Rhombus Sums in a Grid Today’s problem was a matrix + geometry + prefix sum optimization challenge 🔥 💡 Key Insight: A rhombus is basically a rotated square, and we only need the border sum, not the entire area. 👉 Brute force works, but it’s slow. So we optimize using diagonal prefix sums. 🔍 Core Approach: 1️⃣ Understand Rhombus Shape Defined by a center and a “radius” Four edges → top, right, bottom, left 2️⃣ Efficient Border Sum Use diagonal prefix sums to quickly calculate edges Avoid recomputing each cell repeatedly 3️⃣ Track Top 3 Unique Sums Use a set or priority structure Keep only the largest 3 distinct values 🔥 What I Learned Today: Geometry-based problems require visual thinking Prefix sums are powerful beyond simple arrays Optimization matters when dealing with nested loops 📈 Challenge Progress: Day 16/100 ✅ Still consistent, still growing! LeetCode, Matrix, Prefix Sum, Geometry, Optimization, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #PrefixSum #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Keeping it Simple: Solving the "Mirror Distance" Problem! 🧩 I recently tackled an interesting problem on LeetCode: Mirror Distance of an Integer. 🔍 The Challenge: Find the "Mirror Distance," which is the absolute difference between an integer n and its reverse. 🧪 Example: Input: n = 25 Reverse: 52 Calculation: |25 - 52| = 27 ⚙️ My Approach: 1️⃣ Reverse the digits: Used a simple while loop to extract digits and rebuild the number in reverse. 2️⃣ Handle Constraints: Used long long to prevent potential overflow since n can go up to 10⁹. 3️⃣ Absolute Difference: Calculated the final result using the abs() logic. 💡 Insight: Sometimes, the most satisfying part of coding is finding a clean and efficient solution to a straightforward problem. 💻 Keep coding! 🚀 #LeetCode #CodingChallenge #DataStructures #Algorithms #ProblemSolving #Cpp #SoftwareEngineering #DailyCoding
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 90 of My #100DaysOfCode Challenge Today, I worked on the Quicksort Partition Algorithm — a powerful concept from sorting techniques that uses the divide-and-conquer approach. Instead of fully sorting the array, this problem focused on partitioning: 👉 Selecting a pivot (first element) 👉 Dividing the array into: • Elements less than pivot • The pivot itself • Elements greater than pivot 💡 Example: Input: 4 5 3 7 2 Output: 3 2 4 5 7 This challenge helped me understand how the core logic of Quicksort works internally before recursion is applied. 🧠 Key Learnings: ✔ Importance of partitioning in efficient sorting ✔ How Quicksort reduces complexity using divide & conquer ✔ Time Complexity for partition step: O(n) Consistency is building momentum — 90 days strong and still going 💪 #Day90 #100DaysOfCode #CodingJourney #DataStructures #Algorithms #Quicksort #CProgramming #ProblemSolving #DeveloperLife
To view or add a comment, sign in
-
🚀 Day 44 of My LeetCode Journey Today’s problem: Serialize and Deserialize Binary Tree At first glance, this looks like just converting a tree to a string… but the real challenge is preserving structure, not just values. 🔍 Key Insights: - You must store null nodes — otherwise the tree shape gets lost. - A simple level-order (BFS) traversal works well. - Queue helps simulate reconstruction during deserialization. 💡 What I learned: - Serialization isn’t about data — it’s about structure + data together. - Missing edge cases (like skewed trees) will break naive solutions. - Clean design matters more than clever tricks here. ⚙️ Approach: - Serialize → BFS traversal + "null" placeholders - Deserialize → Rebuild using queue step by step 📈 Result: Accepted ✅ This problem improved my understanding of: - Trees - BFS - Data representation Consistency > Motivation. See you on Day 46. #leetcode #datastructures #coding #100daysofcode #learning #softwareengineering
To view or add a comment, sign in
-
-
🚀 Day 21 of 100 Days LeetCode Challenge Problem: Flip Square Submatrix Vertically Day 21 brings a clean matrix manipulation problem—simple logic, but important for fundamentals 🔥 💡 Key Insight: We are given: Top-left corner (x, y) Size k 👉 We need to flip the k x k submatrix vertically → Meaning: reverse the order of rows inside that square 🔍 Core Approach: 1️⃣ Identify Submatrix Boundaries Rows: x → x + k - 1 Columns: y → y + k - 1 2️⃣ Swap Rows Vertically Swap: Row x ↔ Row x + k - 1 Row x + 1 ↔ Row x + k - 2 Continue until middle 👉 Only swap elements within column range [y, y + k - 1] 💡 Visualization: Top row ⬇️ becomes bottom Bottom row ⬆️ becomes top 🔥 What I Learned Today: Matrix problems often come down to index manipulation Clear boundary definition avoids mistakes Simple operations can still test precision 📈 Challenge Progress: Day 21/100 ✅ 3 Weeks Consistency Strong! 💪 LeetCode, Matrix Manipulation, Arrays, Simulation, Indexing, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #Arrays #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
Day 44 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Check Palindrome Using Recursion We were given a string s. Task was to check whether it is a palindrome. But using recursion. 💻 Approach (Recursion + Two Pointers) 🔹️Take two pointers: start and end. 🔹️Base case: ▪️If start >= end → return true 🔹️Compare characters at start and end. 🔹️If they are not equal → return false 🔹️If equal → move inward ▪️start + 1 ▪️end - 1 🔹️Call function again for inner substring Keep checking till center. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can simulate two-pointer traversal. ▫️Base condition defines when to stop checking. ▫️Breaking problem into smaller substrings simplifies logic. ▫️Recursive calls use stack space internally. Day 44 completed. Combining recursion with pointers 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
🌲 Day 50/90: Cracking the Code on Binary Tree Views! We are officially past the halfway mark! 🚀 Today was all about changing perspectives—literally. Dealing with Binary Trees can get dizzying, but once you master the "views," the logic starts to feel like second nature. Here’s a breakdown of the logic I tackled today: 🔍 Problems Solved 1. Right Side View: Imagine standing to the right of the tree. Which nodes can you see? I used a modified DFS (Recursive) approach to prioritize the right child, ensuring I only grabbed the first node visible at each level. 2. Bottom-Left Most Element: This one is a classic. It’s not just the leftmost node; it’s the leftmost node on the very last level. A simple BFS (Level Order Traversal) made this a breeze. 3. Top View: This was the boss battle of the day! I used Vertical Level Order Traversal with a coordinate system (hd, level). By using a Map to store the first node encountered at each horizontal distance, I captured exactly what’s visible from the "sky." 💡 Key Takeaway: For tree "view" problems, Level Order Traversal is your best friend. If you can visualize the tree on a 2D coordinate plane, you can solve almost anything. Current Status: 50 days down, 40 to go. The momentum is real. #100DaysOfCode #DataStructures #Algorithms #BinaryTree #SoftwareEngineer #Vlog #CodingLife #LeetCode #TechJourney
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