🔥 DSA Challenge – Day 119/360 🚀 📌 Topic: Recursion / Math 🧩 Problem: Pow(x, n) Problem Statement: Find x raised to the power n (xⁿ) efficiently, even for large values of n. 🔍 Example: Input: x = 2, n = 5 Output: 32 💡 Approach: Optimized (Binary Exponentiation) 1️⃣ Step 1 – If n is negative, convert → x = 1/x and n = -n 2️⃣ Step 2 – Recursively calculate half = power(x, n/2) 3️⃣ Step 3 – • If n is even → return half × half • If n is odd → return half × half × x ⏱ Complexity: Time: O(log n) Space: O(log n) 📚 Key Learning: Breaking a problem into halves can drastically improve performance 🚀 #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #119DaysOfCode #LeetCode
Dileep Kumar Maurya’s Post
More Relevant Posts
-
🔥 DSA Challenge – Day 131/360 🚀 📌 Topic: Backtracking / Recursion 🧩 Problem: N-Queens Problem Statement: Place N queens on an N×N chessboard such that no two queens attack each other. 🔍 Example: Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."], ["..Q.","Q...","...Q",".Q.."]] 💡 Approach: Optimized Backtracking (Hashing) 1️⃣ Step 1 – Try placing a queen column by column 2️⃣ Step 2 – Use arrays to check if row & diagonals are safe in O(1) 3️⃣ Step 3 – Place queen → recurse → backtrack if needed ⏱ Complexity: Time: O(N!) Space: O(N) + recursion stack 📚 Key Learning: Using hashing for rows & diagonals avoids repeated checks and makes backtracking much faster ⚡ #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #131DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 120/360 🚀 📌 Topic: Math + Recursion 🧩 Problem: Count Good Numbers Problem Statement: Count total valid numbers of length n where even indices have 5 choices and odd indices have 4 choices. 🔍 Example: Input: n = 4 Output: 400 💡 Approach: Optimized (Binary Exponentiation) 1️⃣ Step 1 – Count even positions → use (n + 1) / 2 2️⃣ Step 2 – Count odd positions → use n / 2 3️⃣ Step 3 – Compute power using fast exponentiation and multiply ✔ Use formula: 5^(ceil(n/2)) × 4^(floor(n/2)) ✔ Apply modulo to handle large numbers ✔ Use recursion to reduce time complexity ⏱ Complexity: Time: O(log n) Space: O(log n) 📚 Key Learning: Binary Exponentiation helps reduce power calculation from O(n) to O(log n), which is very useful in large constraints problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
#CodeEveryday — My DSA Journey | Day 13 🧩 Problem Solved: Kth Missing Positive Number (LeetCode #1539) 💭 What I Learned: Used binary search to efficiently find the k-th missing positive number. Key idea: 👉 At any index mid, the number of missing elements before it is: arr[mid] - (mid + 1) At each step: ✔️ Calculated how many numbers are missing till mid ✔️ Adjusted search space based on whether it’s less than or greater than k Finally used low + k to compute the answer. This helped me understand how to transform a problem into a mathematical observation + binary search. ⏱ Time Complexity: O(log n) 🧠 Space Complexity: O(1) ⚡ Key Takeaways: ✔️ Binary search can be applied on derived values, not just indices ✔️ Identifying patterns like “missing count till index” simplifies problems ✔️ Mathematical insight + binary search = optimal solution 💻 Language Used: Java ☕ 📘 Concepts: Binary Search · Math Insight · Arrays · Optimization #CodeEveryday #DSA #LeetCode #Java #BinarySearch #ProblemSolving #Algorithms #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Day 22 of My DSA Journey Today I solved an important Binary Search problem: 👉 Find First and Last Position of Element in Sorted Array 🧩 Problem Understanding Given a sorted array and a target value, we need to find the starting and ending position of the target element. If the target is not present, return [-1, -1]. 🔍 Approach I Used (Binary Search x2) Instead of linear search, I used Binary Search twice: ✔️ First Binary Search → to find the first occurrence ✔️ Second Binary Search → to find the last occurrence 💡 Trick: Even after finding the target, we don’t stop — we continue searching on left/right side to get the boundary indices. ⚡ Why this approach? Because the array is sorted → Binary Search reduces time complexity drastically. ⏱ Time Complexity: O(log n) 📦 Space Complexity: O(1) 🔥 Key Learning Binary Search is not just for finding elements — it can also be used to find boundaries, ranges, and conditions. Consistency is the real game changer 💪 One problem at a time! #DSA #BinarySearch #LeetCode #Java #ProblemSolving #100DaysOfCode #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 18 of My DSA Journey Today I worked on a basic math problem: 👉 Greatest Common Divisor (GCD) 💡 Problem: Find the largest number that divides both given numbers perfectly. 🧠 Approach: Iterate from 1 to min(a, b) Check which number divides both values Keep updating the maximum divisor ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Key Learning: Understanding basic number theory concepts is important for solving many optimization problems. Next step: exploring more efficient approaches like Euclid’s Algorithm 🚀 Consistency matters 💪 #DSA #Java #CodingJourney #100DaysOfCode #Math #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 7/100 – DSA Journey Today’s focus was on implementing a classic and important problem in number theory — Armstrong Numbers — using Java. 🔍 What I built: A program to find all Armstrong numbers within a given range (100 to 2000). 💡 Approach Breakdown: Iterated through each number in the range Counted the number of digits Extracted each digit and computed its power using Math.pow() Summed the results and compared with the original number Printed the number if it satisfies the Armstrong condition ⚙️ Key Concepts Used: Loops (while, for) Mathematical logic (digit extraction, power calculation) Function design for reusability Clean iteration over a range 📌 Output Observed: 153, 370, 371, 407, 1634 📈 Learning Insight: This problem strengthened my understanding of number manipulation and algorithmic thinking, which are fundamental in DSA and frequently asked in interviews. 🔥 Consistency is the key — building problem-solving skills step by step! #Day7 #100DaysOfCode #DSA #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnInPublic 🙌 Tagging: 10000 Coders Pathulothu Navinder
To view or add a comment, sign in
-
-
Day 39 #SDE Problems on mathematical optimization and dynamic programming on strings. Solved: • Count Good Numbers • Word Break Key Learning: • “Count Good Numbers” uses fast exponentiation (binary exponentiation) to efficiently compute large powers under modulo. • “Word Break” is a classic DP problem, where we check if a string can be segmented using a dictionary — reinforcing recursion + memoization patterns. #LeetCode #DSA #DynamicProgramming #Recursion #Algorithms #Java #SoftwareEngineering
To view or add a comment, sign in
-
🚀 DSA Preparation 💪 Solved this problem in my first attempt 🎯 Focused on finding the closest index using simple traversal and distance calculation. A good exercise to strengthen array fundamentals and logical thinking 🔥 🧠 Problem 🔎 Minimum Distance to the Target Element Given an array nums, a target, and a start index: 👉 Find an index i such that nums[i] == target 👉 Return the minimum absolute difference |i - start| 📌 It is guaranteed that the target exists in the array. Example Input: nums = [1,2,3,4,5], target = 5, start = 3 Output: 1 Input: nums = [1], target = 1, start = 0 Output: 0 ⚡ Key Learning 📌 Traverse the array and track minimum distance 📌 Use absolute difference for comparison 📌 Time Complexity: O(n) 📌 Space Complexity: O(1) First attempt success ✅ Improving DSA step by step 🚀 #DSA #LeetCode #Arrays #ProblemSolving #Java #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Series #1 — Closest Target in Circular Array Today I solved an interesting problem involving circular arrays + shortest distance logic. 🧠 Key Insight: Instead of simulating movement, we can compute distance using modulo. 👉 Forward distance: (i - start + n) % n 👉 Backward distance: (start - i + n) % n Take the minimum of both — done in O(n) time ⚡ 📌 Complexity: O(n) time | O(1) space 💡 Learning: Circular problems often look tricky, but math simplifies everything. 🔥 Building consistency with: #DSA #Java #Coding #PlacementPreparation #100DaysOfCode If you’re on the same path, let’s connect and grow 🤝
To view or add a comment, sign in
-
-
Day 37 #SDE backtracking and subset generation patterns. Solved: • Power Set in Lexicographic Order • Combination Sum Key Learning: • Generating a power set strengthens understanding of recursion trees and how to systematically explore all subsets in a structured (lexicographic) manner. • “Combination Sum” reinforces backtracking with choices and pruning, where we explore combinations while respecting constraints like target sum. #LeetCode #DSA #Backtracking #Recursion #Algorithms #Java #SoftwareEngineering
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