⚡ 𝗗𝗮𝘆 𝟴𝟴 𝗼𝗳 𝗠𝘆 𝟭𝟬𝟬 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗗𝗦𝗔 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲! Today’s problem was rooted in number theory and divisor logic — a great way to strengthen mathematical foundations. 📌 Problem Solved: 1️⃣ Check Whether a Number is a Perfect Number A number is called perfect if it is equal to the sum of its proper divisors (excluding the number itself). Example: 6 → Divisors: 1, 2, 3 Sum = 6 ✅ (Perfect Number) ✨ Key Learnings: 🔹 Instead of checking all numbers from 1 to n-1, we can optimize by iterating only up to √n. 🔹 For every divisor i, we add both i and n/i (if distinct) to the sum. 🔹 Time Complexity improved to: ✅ O(√n) instead of O(n) 🔹 Important edge case: Numbers ≤ 1 cannot be perfect numbers. 🧠 Big Takeaway: Many math-based problems become efficient once you understand divisor symmetry. Day 88 completed — number theory getting stronger! 💪🔥 #100DaysOfCode #DSA #Java #NumberTheory #MathLogic #ProblemSolving #InterviewPreparation #LearningInPublic #Developers
Perfect Number Checker Optimized with Divisor Symmetry
More Relevant Posts
-
🚀 DSA Insight — Reversing an Array the Optimal Way A very common problem, but also a great test of fundamentals. Many beginners create a new array or use extra memory to reverse elements… But the most efficient solution doesn’t require any extra space 👇 🏆 Optimal Approach — Two Pointer Technique Use two pointers: left → start of array right → end of array Swap elements and move inward. swap(arr[left], arr[right]) left++ right-- We stop when pointers meet in the middle. 📊 Complexity MetricValueTime ComplexityO(n)Space ComplexityO(1)Swapsn/2💡 Why It’s Optimal To reverse an array, every element must move at least once → O(n) is unavoidable. This approach also avoids extra memory, making it optimal in both time and space. 🧠 Simple logic + strong fundamentals = efficient coding #DSA #Algorithms #CodingInterview #Java #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
DSA Journey — Day 22 Today I solved the Balanced Binary Tree problem and learned an important optimization concept. -> Problem: Check whether a binary tree is height-balanced (difference between left and right subtree height ≤ 1 for every node). -> Key Learning: Instead of calculating height separately for each node (which gives O(n²) complexity), we can combine height calculation + balance checking in a single DFS traversal to achieve O(n) time. Core Insight: Return -1 immediately when a subtree is unbalanced. This avoids unnecessary computations and makes the solution efficient. Why this matters: This problem taught me how to: Optimize brute force recursion Detect early stopping conditions Write cleaner recursive logic Growth Mindset: Every tree problem is improving my recursion intuition and problem-solving speed. #DSA #Java #CodingJourney #Recursion #LearningInPublic #WomenInTech
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟮𝟴 – 𝗝𝗮𝘃𝗮 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗦𝗼𝗹𝘃𝗶𝗻𝗴 & 𝗗𝗦𝗔 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 Consistency builds capability. Today marks Day 28 of my continuous practice in Java Problem Solving and Data Structures & Algorithms. Each day is helping me strengthen my fundamentals and improve my logical thinking. 🔹 Concepts Practiced Today - Binary Search – understanding how it significantly reduces time complexity compared to Linear Search - Floor of a Number - Ceil of a Number - Finding the Span of elements - Leader in an Array 🧪 Practice Test Focus Worked on array and sub-array based logical problems such as: - Printing all elements whose index position sum is divisible by m1 and m2 - Writing a program to identify subarrays where the difference between the maximum and minimum element equals k These exercises are helping me develop a deeper understanding of algorithm efficiency, edge cases, and array traversal logic. 💡 Every problem solved is another step toward becoming a stronger developer. #Java #DSA #ProblemSolving #LearningInPublic #ProgrammingJourney #ComputerScience #DeveloperGrowth
To view or add a comment, sign in
-
-
LeetCode 268 – Missing Number Today I solved “Missing Number”, a simple but powerful DSA problem. Problem summary: Given an array containing n distinct numbers in the range [0, n], return the one number that is missing from the array. What I learned from this problem: • We can solve it using sorting (but that’s not optimal) • A better approach is using the Sum Formula Expected sum = n × (n + 1) / 2 Missing number = Expected sum − Actual sum • Time Complexity: O(n) • Space Complexity: O(1) Another interesting approach is using XOR, which avoids overflow and also runs in O(n) time. This problem reminded me that sometimes the best solution is not complicated — it’s about recognizing mathematical patterns. Small problems like this build strong problem-solving intuition. #DSA #LeetCode #ProblemSolving #Java #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Most people solve this in O(n²). I almost did too. But today I learned a simple trick that makes it O(n). 🚀 Day 55/365 — DSA Challenge Solved: Find Pivot Index The problem is simple: Find an index where left sum == right sum Example: [1,7,3,6,5,6] → answer = 3 My first thought: For every index → calculate left sum & right sum Works… But too slow ❌ Then I realized something: You don’t need to recalculate everything. You already have the total sum. 💡 Key idea: Right sum = totalSum - leftSum - current So instead of nested loops… You just keep updating leftSum. One pass. Clean logic. Optimal solution. ⏱ O(n) time 📦 O(1) space This problem taught me: Simple problems still test your thinking. Optimization matters. And most importantly… Don’t overcomplicate. Code 👇 https://lnkd.in/dad5sZfu #DSA #LearningInPublic #Java #Coding #LeetCode #Consistency #365Days365DSAProblems
To view or add a comment, sign in
-
-
🔥 Day 346 – Daily DSA Challenge! 🔥 Problem: ⚡ Total Hamming Distance The Hamming distance between two integers is the number of bit positions where they differ. Given an integer array nums, return the sum of Hamming distances between all pairs. 💡 Key Insight — Count Bits Column-wise Instead of comparing every pair (O(n²)), analyze each bit position independently. For a given bit: Let ones = number of elements with that bit = 1 Let zeros = n - ones Each pair of (1,0) contributes 1 to Hamming distance. Total contribution for that bit: Sum this for all 32 bits. For each bit column we count ones × zeros and add them. ⚡ Algorithm ✅ Iterate through 32 bit positions ✅ Count how many numbers have that bit set ✅ Compute contribution ones × (n − ones) ✅ Add to result ⚙️ Complexity ✅ Time Complexity: O(32 × n) ≈ O(n) ✅ Space Complexity: O(1) 💬 Challenge for you 1️⃣ Why does this approach avoid pairwise comparison? 2️⃣ How would this change for 64-bit numbers? 3️⃣ Can this be extended to compute XOR sum of all pairs? #DSA #Day346 #LeetCode #BitManipulation #HammingDistance #Math #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 86 of My DSA Journey | Subsets – Recursion ➡️ Bit Manipulation 💡 Yesterday, I solved the Subsets problem (LeetCode 78) using recursion (backtracking). Today, I challenged myself to solve the same problem using a different approach — Bit Manipulation 🔥 🔹 What changed? Instead of recursion, I used bit masking to generate all subsets. Every number from 0 to 2^n - 1 represents a subset in binary form. 👉 Core idea: (i & (1 << j)) != 0 This checks whether the j-th element should be included in the subset. 📌 Example: nums = [1,2,3] i = 5 → binary (101) Subset → [1,3] ⚡ Key Learning: One problem can have multiple approaches Recursion = intuitive Bit manipulation = optimized & clever Strengthened my understanding of binary concepts ⏱️ Time Complexity: O(n * 2^n) 📦 Space Complexity: O(2^n) Consistency is the key — learning, applying, and improving every single day 💯 #Day87 #DSA #Java #BitManipulation #Recursion #LeetCode #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
Daily DSA Update – Day 26 Solved: Add Binary (LeetCode) Today’s problem was about adding two binary strings and returning their sum as a binary string. Problem: Given two binary strings a and b, return their sum as a binary string. Approach: I simulated the same process we use while doing binary addition manually. Starting from the end of both strings, I added corresponding digits along with a carry value. After calculating the sum, I appended the result bit and updated the carry. Finally, I reversed the result to get the correct binary order. Key Learning: Problems like this highlight the importance of understanding how operations work internally rather than relying on built-in conversions. What this strengthened: • String traversal from right to left • Handling carry in binary operations • Using StringBuilder for efficient string manipulation • Implementing mathematical logic in code Each daily problem adds a small but meaningful improvement in problem-solving ability. On to the next challenge. #DSA #DataStructures #Algorithms #Java #LeetCode #ProblemSolving #CodingJourney #TechLearning
To view or add a comment, sign in
-
Understanding Tree Structure Beyond Just Values Today I solved the Same Tree problem while practicing Binary Trees. While working on Same Tree, I realized something important: 👉 Two trees are not the same just because they contain the same values. 👉 Their structure must also be identical. 💡 Key Learnings: Tree comparison requires checking both node values and structure. Recursive DFS makes the solution clean and intuitive. Base cases (both null, one null, value mismatch) are critical. Logical clarity matters more than writing complex code. This problem strengthened my understanding of: ✔ Recursive thinking ✔ Base condition handling ✔ Structural comparison in trees ✔ Writing clean and interview-ready DFS code Every tree problem improves not just coding skills, but problem-solving mindset. #DSA #Java #BinaryTree #DFS #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 5/50 – LeetCode Challenge 🧩 Roman to Integer Today’s problem focused on converting a Roman numeral into its integer equivalent — a great exercise in understanding patterns and rules in string processing. 📌 Problem Summary: Given a Roman numeral, convert it into an integer. Roman numerals follow specific rules, especially the subtraction rule: IV = 4 IX = 9 XL = 40 CM = 900 🔍 Approach Used: Mapped each Roman symbol to its integer value Traversed the string from left to right Compared current value with the next value If the next value is greater → subtract Otherwise → add This helps correctly handle cases like IV, IX, XL, etc. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 Key Learning: ✔️ Understanding rule-based logic ✔️ Handling special subtraction cases ✔️ Efficient string traversal ✔️ Using maps for faster lookups A simple-looking problem that strengthens logical thinking and pattern recognition. Consistency is the real progress 🚀 🔗 Problem Link: https://lnkd.in/g4Z36z3c #50DaysOfLeetCode #LeetCode #DSA #Java #Strings #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
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