Day 19 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Print All Prime Factors of a Number We were given an integer N. We had to print all its prime factors. This one was more number theory based. Let’s understand it simply. ◾️Imagine you want to break a number into its smallest building blocks. ◾️Those building blocks must be prime. ◾️When you multiply them back, you should get the original number. That’s prime factorization. --- 💻 Brute Force Approach 🔹️Start from 2 till n. 🔹️Check if i divides n. 🔹️If yes, check if i is prime. 🔹️If prime, add it to list. Time Complexity: Higher. Because we check many numbers. Works. But not efficient. --- 💻 Optimal Approach 🔹️Start from 2 till √n. 🔹️If i divides n, add it to list. 🔹️Keep dividing n by i in a while loop. 🔹️Remove repeated factors. 🔹️Continue till √n. 🔹️If remaining n > 1, it is also a prime factor. Time Complexity: O(√N) Space Complexity: O(√N) Much better than checking till n. --- 📚 What I learned today: ▫️We don’t need to check till n. √n is enough. ▫️Repeated division reduces unnecessary checks. ▫️Prime factor problems are about observation. ▫️Number theory concepts are important for coding interviews. Day 19 completed. Math + logic together today 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
Prime Factors Challenge: Brute Force vs Optimal Approach
More Relevant Posts
-
🚀 Day 8 of 100 Days LeetCode Challenge Problem: Find Unique Binary String Today’s problem introduced a very interesting concept from theoretical computer science—but applied in a simple coding way. 💡 Key Insight (Diagonal Trick): Instead of generating all possibilities, we can construct a guaranteed unique string. 👉 Idea: Look at the i-th string’s i-th character Flip it (0 → 1, 1 → 0) Build a new string from these flipped bits 🔥 This ensures: The new string differs from every string at least in one position So it’s guaranteed NOT present in the array 🔍 Why This Works: This is based on Cantor’s Diagonalization concept—ensuring uniqueness by construction. 🔥 What I Learned Today: Smart construction > brute force generation Some problems have mathematical insights hidden inside Thinking differently can reduce complexity drastically 📈 Challenge Progress: Day 8/100 ✅ Consistency streak continues! LeetCode, Binary Strings, Greedy, Mathematical Insight, Cantor Diagonalization, DSA Practice, Coding Challenge, Problem Solving, Algorithms #100DaysOfCode #LeetCode #DSA #CodingChallenge #BinaryStrings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 6 of Coding Journey Today I learned a powerful problem-solving technique: Two Pointer Technique 👇 Instead of using nested loops (O(n²)), we can solve certain problems in O(n) time using two pointers. 💡 How it works: Start one pointer at the beginning (L) Start another pointer at the end (R) Move them based on a condition (like sum comparison) 👉 Example: Find pair with sum = 6 1 + 6 = 7 → too big → move right pointer 1 + 4 = 5 → too small → move left pointer 2 + 4 = 6 ✅ Found! 🔥 Why this is useful: Improves efficiency Common in interviews Used in arrays, strings, and sliding window problems 📌 Key takeaway: “Smart thinking beats brute force.” I’m getting better every day. Let’s keep building 💪 #Day6 #CodingJourney #DataStructures #Algorithms #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 What a Problem! Some questions don’t just test your coding skills — they stretch your thinking, sharpen your recursion game, and remind you why you started grinding DSA in the first place. This one was a masterclass in Recursion + Strings 🔁🧵 A solid mid-level problem — perfect for both beginners building fundamentals and experienced problem solvers chasing that 💯 runtime efficiency. As developers, we love building products from scratch 🛠️ But stepping away from development and diving deep into pure problem-solving? That’s where the real mental workout happens. That’s where growth hides. Strings, Recursion, Arrays, Data Structures — these aren’t optional tools. You might delay them. You might underestimate them. But trust me — you can’t escape them 😄 There’s something addictive about breaking down a recursive pattern, understanding symmetry, and optimizing without brute force. That dopamine hit when it finally clicks? Unreal ⚡ On to the next challenge. In search of Dynamic Programming and Trees, somehow I got even more attached to Strings 🌳➡️🧠 #DSA #ProblemSolving #Recursion #Strings #CodingJourney #LeetCode #SoftwareEngineering #KeepGrinding 💪
To view or add a comment, sign in
-
-
𝗧𝗪𝗢 𝗠𝗢𝗡𝗧𝗛𝗦 𝗜𝗡𝗧𝗢 𝗡𝗘𝗘𝗧𝗖𝗢𝗗𝗘 𝟭𝟱𝟬 Lately, I’ve been focusing on patterns over problem count. Instead of checking boxes, I am trying to understand why an approach works. Arrays, hashmaps, sliding window, two pointers, the same ideas show up in different but related problems. I’m still using NeetCode as my guide and solution reference, working through problems one at a time. I realized every day is not about finishing a new problem. Sometimes, I go back to one I already tried because I didn’t fully understand it (or remember the pattern) the first time. Here’s what practice actually looks like for me: - Some days I tackle a new problem - Some days I redo one I half-understood - I always go back to the earlier problems - I split time between DSA (Python) and SQL - I write/draw out my approach first, then think through it Most of my code right now could be written by AI. But actually solving problems myself (figuring out the logic, tracing cases, thinking through mistakes) keeps my brain active and my critical thinking sharp. It’s basic, but it’s fresh and rewarding. LeetCode: https://lnkd.in/gG7ZuCRM #LearningInPublic #LeetCode #NeetCode #DSA #Python #SQL #ProblemSolving #DataEngineering #DataScience #DataAnalytics #OpenToWork
To view or add a comment, sign in
-
🚀 Day 11 of My Coding Journey – Single Element in a Sorted Array Today I learned how to solve the problem of finding the single non-duplicate element in a sorted array. 🔹 In this problem, every element appears twice except one element, and we need to find that single element efficiently. Instead of using a simple linear search, we apply Binary Search to achieve an optimized time complexity of O(log n). 💡 Key Idea: In a sorted array, pairs of elements follow a pattern: - Before the single element, pairs start at even indices - After the single element, this pattern breaks Using this observation, we can decide whether to move left or right in the array during binary search. 📌 Example: Array: "[1, 1, 2, 2, 3, 4, 4, 5, 5]" Output: "3" This problem helped me understand how patterns in arrays can be used to optimize searching techniques. Consistency is the key — learning something new every day! 💻✨ #Day11CodingChallenge #DSA #BinarySearch #CodingJourney #ProblemSolving #LearningInPublic #TechJourney #Consistency
To view or add a comment, sign in
-
-
Day 59 - LeetCode Journey Solved LeetCode 41: First Missing Positive (Hard) today — a problem that truly tests deep understanding of arrays, indexing, and optimization. This isn’t just about coding, it’s about thinking in-place, minimizing space, and using constraints smartly. 💡 Core Idea: Instead of using extra space, we treat the array itself as a hash map and place each element at its correct index (value → index mapping). This transforms the problem into finding the first index where the expected value is missing. ⚡ Approach Highlights: • Cyclic placement of elements to their correct positions • Ignoring invalid values (≤ 0 or > n) • Swapping until every valid number is at its right index • Final scan to find the first missing positive 🚀 Why this is powerful: • Achieves O(n) time complexity • Uses O(1) extra space • Demonstrates in-place hashing technique • Strengthens understanding of index manipulation patterns These are the kinds of problems that build real interview-level thinking — not just solving, but optimizing 💯 Every hard problem pushes boundaries a little further. Slow progress is still progress. ✅ Improved understanding of in-place algorithms ✅ Better optimization mindset ✅ Stronger grip on edge cases Still learning. Still improving. Still coding 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #DataStructures #Arrays #Optimization #InterviewPreparation #KeepCoding #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Day 5 of 100 Days LeetCode Challenge Problem: Minimum Changes To Make Alternating Binary String Today’s problem is a perfect example of pattern comparison + greedy thinking. 💡 Key Insight: An alternating string can only be in two possible forms: "010101..." "101010..." 🔍 Approach: Compare the given string with both patterns Count mismatches for each pattern The minimum mismatch count = minimum operations required 👉 No need for complex logic—just check both possibilities and pick the best. 🔥 What I Learned Today: Always check if a problem has limited possible patterns Comparing with ideal cases can simplify logic Greedy approach helps in minimizing operations quickly 📈 Challenge Progress: Day 5/100 ✅ Strong consistency! LeetCode, Greedy Algorithm, Strings, Pattern Matching, DSA Practice, Coding Challenge, Problem Solving, Algorithm Thinking, Optimization #100DaysOfCode #LeetCode #DSA #CodingChallenge #GreedyAlgorithm #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 4 of 100 Days LeetCode Challenge. Problem: Special Positions in a Binary Matrix Today’s problem focused on matrix traversal + counting logic—simple concept, but requires careful observation. 💡 Key Insight: A position (i, j) is special if: mat[i][j] == 1 All other elements in the same row and column are 0 🔍 Efficient Approach: Count number of 1’s in each row Count number of 1’s in each column A position is special only if: Row count = 1 Column count = 1 👉 This avoids unnecessary repeated checks and improves efficiency. 🔥 What I Learned Today: Preprocessing (row & column counts) simplifies problems Avoid brute force → think in terms of frequency/counting Clean logic > complex code 📈 Challenge Progress: Day 4/100 ✅ Staying consistent! LeetCode, Matrix Problem, Arrays, Counting Technique, DSA Practice, Coding Challenge, Problem Solving, Algorithm Thinking, Optimization #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 End of the Week LeetCode Practice Wrapping up this week’s coding practice with another problem from the array collection on LeetCode: Remove Duplicates from Sorted Array. It’s the end of the week, and I’m glad to say I’ve already knocked down 2 problems while continuing to sharpen my problem-solving skills. 🔎 Problem Overview Given a sorted array, the task is to remove duplicates in-place so that each element appears only once. The function should return the number of unique elements (k), and the first k positions of the array should contain those unique values. The challenge is doing this without using extra space, meaning we must modify the original array efficiently. 🧠 Approach Because the array is already sorted, duplicate values appear next to each other. This makes the two-pointer technique a clean and efficient solution. • Pointer i tracks the position of the last unique element • Pointer j scans through the array • When a new unique value appears, i moves forward and we update the array This keeps the solution efficient with: • Time Complexity: O(n) • Space Complexity: O(1) ⚙️ Performance • Runtime: 4 ms (Beats 42.04%) • Memory Usage: 13.92 MB (Beats 38.66%) 💡 I’ve featured the full implementation in my LeetCode library on my LinkedIn profile, where I’m documenting my problem-solving journey. Feel free to check it out there. 📊 Week Summary ✔ Solved 2 LeetCode problems ✔ Practiced array manipulation and pointer techniques ✔ Continued building consistency in coding practice Now it's time to reset, recharge, and start getting ready for next week’s challenge. #LeetCode #Algorithms #Python #DataScienceJourney #MachineLearning #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
🥷 Day 309 of My 365 LeetCode Challenge is done! 💥 Kicked off strong, solved my problem, and the coding vibe is awesome! 🧠 📌 LeetCode 3296 – Minimum Number of Seconds to Make Mountain Height Zero Another interesting problem that combines binary search with mathematical optimization. Challenges like this help improve the ability to transform real-world style problems into efficient algorithmic solutions. 🧠 🔍 Problem Overview We are given: mountainHeight → the total height that needs to be reduced to 0 workerTimes → an array representing the time each worker takes to perform work Workers operate simultaneously, and the time required by a worker increases as they reduce more height. For a worker with time t: Reducing height by 1 takes t seconds Reducing height by 2 takes t + 2t seconds Reducing height by 3 takes t + 2t + 3t seconds The goal is to determine the minimum number of seconds required for all workers combined to reduce the mountain height to zero. 💡 Key Idea Behind the Solution Instead of simulating every second, we use Binary Search on Time. Steps: 1️⃣ Guess a time T. 2️⃣ Calculate how much total height all workers can reduce within T. 3️⃣ If the reduced height is enough, try a smaller time. 4️⃣ Otherwise, increase the time. This approach efficiently finds the minimum time required. ⚙️ Concepts Used ✔ Binary Search on Answer ✔ Mathematical Derivation ✔ Greedy Contribution Calculation ✔ Optimization Techniques 🧠 Key Takeaway Many problems that seem like simulation tasks can actually be solved much faster using binary search on the answer space. Recognizing these patterns is key to writing efficient algorithms. 🔥 85 Days of Consistency! Daily problem solving continues to sharpen algorithmic thinking and pattern recognition. #LeetCode #DSA 🧠 #BinarySearch #Algorithms #ProblemSolving #CodingJourney #InterviewPrep 🚀
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