Dileep Kumar Maurya’s Post

🔥 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

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories