🗓 Day 61 / 100 – #100DaysOfLeetCode 📌 Problem 1390: Four Divisors Today’s problem combined number theory fundamentals with careful iteration. The task was to scan through an array and compute the sum of divisors only for those numbers that have exactly four distinct divisors. 🧠 My Approach: For each number in the array: Iterated from 1 to √x to find divisor pairs efficiently. Whenever i divides x, added both i and x / i to a set to ensure uniqueness. Accumulated the sum of these divisors while tracking how many unique divisors were found. After processing a number, checked: If it had exactly 4 divisors, added its divisor sum to the final answer. Otherwise, ignored it. Using the square-root optimization keeps the solution efficient even for large values. 💡 Key Learning: This problem reinforced: ✔ efficient divisor enumeration using √n optimization ✔ using sets to avoid duplicate divisors ✔ applying number theory concepts in coding problems ✔ filtering results based on strict conditions A solid reminder that understanding divisor patterns can simplify many math-based problems in DSA 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Math #NumberTheory #Divisors #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
Four Divisors Sum with √n Optimization
More Relevant Posts
-
🧠 𝗡𝗲𝘄 𝘁𝗵𝗶𝗻𝗴 𝗲𝘃𝗲𝗿𝘆 𝗱𝗮𝘆 𝘄𝗵𝗶𝗹𝗲 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗣𝘆𝘁𝗵𝗼𝗻 Today’s practice was about something we often overlook: 👉𝗛𝗖𝗙 (𝗚𝗖𝗗) & 𝗟𝗖𝗠 It looks like basic math. But implementing it in code makes you 𝘁𝗵𝗶𝗻𝗸 𝗱𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁𝗹𝘆. 🔍 𝗪𝗵𝗮𝘁 𝗜 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝗱 𝘁𝗼𝗱𝗮𝘆: • Finding HCF using conditions and loops • Understanding why checking up to the minimum number works • Using HCF to calculate LCM logically • Connecting math formulas with real code 💡 𝗪𝗵𝗮𝘁 𝘁𝗵𝗶𝘀 𝗿𝗲𝗺𝗶𝗻𝗱𝗲𝗱 𝗺𝗲: • Simple problems build strong foundations • Logic matters more than shortcuts • Revisiting basics improves problem-solving confidence No big project today. Just one small concept — understood a little better. Learning doesn’t have to be fast. It just has to be 𝙘𝙤𝙣𝙨𝙞𝙨𝙩𝙚𝙣𝙩. New thing every day. One step at a time 🚀 What basic concept are you practicing right now? #Python #LearningByDoing #ProblemSolving #CodingBasics #DSA #DeveloperJourney #Consistency #LearningToCode #TechCareers #LinkedInGrowth
To view or add a comment, sign in
-
-
Daily Coding Insight: Minimizing Maximum Pair Sum Just solved an interesting problem on LeetCode (#1877) that teaches a valuable pattern: Problem: Given an array of even length, form pairs to minimize the maximum pair sum. Key Insight: The optimal approach isn't intuitive at first! You might think of pairing similar numbers, but the actual solution is: Sort the array Pair smallest with largest (two-pointer approach) Why this works: By balancing each pair (small + large), we prevent any single pair from having an excessively large sum. Pattern Recognized: 🔹 Greedy + Sorting + Two Pointers 🔹 Time: O(n log n), Space: O(1) #Coding #Algorithm #ProblemSolving #Python #DataStructures #LeetCode #Programming #SoftwareEngineering #Tech #Learning
To view or add a comment, sign in
-
-
✅ Day 16 of 100 Days LeetCode Challenge Problem: 🔹 #79 – Word Search 🔗 https://lnkd.in/gHeRzA2d Learning Journey: 🔹 Today’s problem shifted from combination generation to grid-based search using DFS. 🔹 The goal was to check whether a given word exists in a 2D board by moving horizontally or vertically between adjacent cells. 🔹 I used Depth-First Search (DFS) with backtracking, starting from each cell that matched the first character of the word. 🔹 To avoid revisiting the same cell in a single path, I temporarily marked the cell as visited and restored it after exploring all directions. Concepts Used: 🔹 Depth-First Search (DFS) 🔹 Backtracking 🔹 Matrix Traversal 🔹 Recursive Search Key Insight: 🔹 Backtracking is not limited to combinatorial problems; it is equally effective for grid traversal and path search problems. 🔹 Marking and restoring visited cells is essential to correctly explore all possible paths. 🔹 Careful boundary checks and base conditions are critical for correctness in recursive grid problems. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 11 of 100 Days LeetCode Challenge Problem: 🔹 #46 – Permutations 🔗 https://lnkd.in/gZPAAxVw Learning Journey: 🔹 Today’s problem focused on generating all possible permutations of a given array. 🔹 The solution is a classic example of applying backtracking to explore all valid states. 🔹 By fixing one element at a time and recursively permuting the remaining elements, every possible ordering is generated. 🔹 Swapping elements in place avoids extra space usage and keeps the implementation clean. 🔹 After each recursive call, reverting the swap ensures the original state is restored for the next iteration. Concepts Used: 🔹 Backtracking 🔹 Recursion 🔹 Depth-First Search (DFS) 🔹 In-place Swapping Key Insight: 🔹 Backtracking systematically explores all possibilities while maintaining control over state changes. 🔹 Restoring state after recursion is critical to avoid corrupting future paths. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 12 of 100 Days LeetCode Challenge Problem: 🔹 #78 – Subsets 🔗 https://lnkd.in/gazZukB6 Learning Journey: 🔹 Today’s problem was about generating all possible subsets (the power set) of a given array. 🔹 I approached it using backtracking, making a binary decision at each index: include or exclude the current element. 🔹 The recursion explores both paths systematically, ensuring no subset is missed. 🔹 Copying the current solution at the base case preserves the state before backtracking continues. Concepts Used: 🔹 Backtracking 🔹 Recursion 🔹 Depth-First Search (DFS) 🔹 Power Set Generation Key Insight: 🔹 Subset problems naturally map to a include/exclude decision tree. 🔹 Backtracking provides a clean and intuitive way to explore all combinations. 🔹 Understanding recursion flow is crucial for mastering combinatorial problems. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
🗓 Day 65 / 100 – #100DaysOfLeetCode 📌 Problem 3799: Word Squares Today’s problem was an interesting mix of string indexing, permutations, and pattern validation. The task was to identify valid 4×4 word squares, where characters align correctly across rows and columns. 🧠 My Approach: Sorted the list of words for consistent ordering. Generated all possible permutations of 4 distinct words. Treated each permutation as: top, left, right, bottom Verified the word-square constraints by checking character alignment: First characters must match across corresponding positions. Last characters must align correctly to complete the square. If all conditions were satisfied, added the group of words to the result list. This direct validation approach works well given the fixed word length and limited input size. 💡 Key Learning: This problem reinforced: ✔ how careful index-based comparisons can enforce structural constraints ✔ using permutations to explore all valid combinations ✔ translating a visual pattern (word square) into precise logical checks It’s a good reminder that many pattern problems are about mapping geometry or structure into indices. Another satisfying problem solved 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Strings #Backtracking #Permutations #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
✅ Day 26 of 100 Days LeetCode Challenge Problem: 🔹 #746 – Min Cost Climbing Stairs 🔗 https://lnkd.in/gzuqP_J3 Learning Journey: 🔹 Today’s problem focused on finding the minimum cost required to reach the top of a staircase. 🔹 I used Dynamic Programming to compute the minimum cost starting from each step and working backward. 🔹 At every step, the decision is to move one or two steps ahead, choosing the path with lower accumulated cost. 🔹 Storing intermediate results avoids redundant calculations and improves efficiency. Concepts Used: 🔹 Dynamic Programming 🔹 Bottom-Up DP 🔹 State Transition 🔹 Optimization Techniques Key Insight: 🔹 Problems involving minimum cost often benefit from a bottom-up approach. 🔹 Comparing future states helps determine the optimal current decision. 🔹 Dynamic Programming simplifies problems that would otherwise be exponential using recursion. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge – Day 4 Problem #1390: Four Divisors (Medium) Today’s problem was one of those that really tested my patience and understanding of time complexity. 🧭 How I Approached the Question: I initially started with a brute-force approach, checking all numbers from 1 to n to find divisors. While this worked for small cases, it quickly became inefficient and failed on larger inputs. I then optimized by: Iterating only up to √n Counting divisors in pairs Breaking early once the divisor count exceeded 4 The key learning moment was realizing that: 👉 A number can have exactly four divisors only when it fits specific mathematical patterns, and we don’t need to enumerate all divisors. Using this insight, I avoided unnecessary loops, skipped perfect squares, and stopped as soon as extra divisors were found — which finally passed all test cases. ⏱ Time Complexity: O(n√k) (with early exits) 📦 Space Complexity: O(1) This problem reinforced an important lesson: 👉 Brute force helps you start, but optimization and math help you finish. 📌 Stay tuned for more daily problem-solving insights and honest coding learnings! #LeetCode #DailyCoding #DataStructures #Algorithms #ProblemSolving #Python #DSA #CodingJourney #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 51 – Mastering Graph Topology (Course Schedule) Today’s practice focused on graph cycle detection using Topological Sorting, a core concept in scheduling and dependency-based problems. 🔹 Problem Solved: Course Schedule Core Idea: Determine whether all courses can be completed given prerequisite dependencies. 🧠 Approach Used: Kahn’s Algorithm (BFS-based Topological Sort) Graph Construction Built an adjacency list where each course points to the courses dependent on it Calculated indegree (number of prerequisites) for each course Queue Initialization Added all courses with indegree = 0 to the queue (no prerequisites) BFS Processing Repeatedly removed courses from the queue Reduced indegree of neighboring courses Added newly unlocked courses to the queue Validation If the number of processed courses equals total courses → No cycle Otherwise → Cycle exists, completion impossible 📌 Key Learnings Topological sorting is essential for dependency resolution Indegree tracking simplifies cycle detection in directed graphs BFS-based solutions are often more intuitive than DFS for scheduling problems Graph problems become easier once visualized as dependencies #Day51 #DSA #Graphs #TopologicalSort #CourseSchedule #LeetCode #Python #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🗓 Day 66 / 100 – #100DaysOfLeetCode 📌 Problem 865: Smallest Subtree with All the Deepest Nodes Today’s problem focused on binary tree depth analysis. The goal was to find the smallest subtree that contains all the deepest nodes in the tree. 🧠 My Approach: Used Depth-First Search (DFS) to compute information bottom-up. For each node, tracked: the maximum depth reachable from that node, and the candidate subtree root that contains all deepest nodes. Compared depths of left and right subtrees: If both sides have the same depth → the current node is the answer. Otherwise, propagated the deeper side upward. Returned the node that satisfies the condition for all deepest nodes. This approach cleanly combines depth calculation with subtree selection in a single traversal. 💡 Key Learning: This problem reinforced: ✔ how returning multiple values from DFS simplifies logic ✔ thinking bottom-up for tree optimization problems ✔ identifying the exact node where depths converge Tree problems often become elegant once the right recursive structure is identified 🌳🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryTree #DFS #TreeTraversal #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
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