Today I learned about an interesting problem: Happy Number 👉 A number is called Happy if: Replace the number by the sum of the squares of its digits Repeat the process If it becomes 1, it's a Happy Number ✅ If it loops endlessly, it's NOT ❌ 💡 Example: 19 → 1² + 9² = 82 82 → 8² + 2² = 68 68 → 6² + 8² = 100 100 → 1² + 0² + 0² = 1 ✅ 🧠 Key Learning: Cycle detection is important here We can use a set or fast & slow pointers to detect loops 💻 This problem helped me understand: ✔ Number manipulation ✔ Loop detection logic ✔ Problem-solving approach Consistency is the key 🔑 — learning something new every day! 👉 Have you solved this problem using a different approach? #DSA #Python #CodingJourney #100DaysOfCode #ProblemSolving #SoftwareDeveloper
Happy Number Problem and Cycle Detection
More Relevant Posts
-
Day 111 Backtracking is starting to feel consistent now. #Day111 🧩 39. Combination Sum How today went: • Used backtracking with index i • Two choices: → stay at i (reuse the same element) → move to i + 1 (try next element) • Track the current total • If total == target → add result • If total > target → stop that path What I realized: This problem is about: → controlling index movement → managing the running total Same pattern, different control. Revision is making it clearer. #LeetCode #DSA #Python #Backtracking #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 13/100 – Understanding Before Solving Today’s problem: Reverse String At first glance, it looks simple—but the real goal is to understand how to solve it efficiently. The challenge is to reverse the string in-place, meaning without using extra memory. Approach Explained: We use the two-pointer technique: One pointer starts from the beginning One from the end Swap characters and move inward This avoids creating a new array and keeps the solution optimal. Time Complexity: O(n) Space Complexity: O(1) Key Learning: Writing code is important, but understanding why it works is what truly builds strong problem-solving skills. One step closer to mastering DSA. #100DaysOfCode #DSA #Learning #ProblemSolving #Python #LeetCode #GrowthMindset
To view or add a comment, sign in
-
-
🧩 DSA Breakdown: Insert Interval One of those problems that looks scary at first, but once you see the pattern — it clicks instantly. The problem: Given a sorted list of non-overlapping intervals, insert a new interval and merge if needed. The trick? Just think in 3 phases: 1️⃣ Add all intervals that END before the new one starts → no overlap, safe to add 2️⃣ MERGE all intervals that overlap → keep expanding the new interval's boundaries 3️⃣ Add everything remaining → they start after the new interval ends ✅ Time: O(n) — single pass ✅ Space: O(n) Currently grinding DSA one problem at a time 💪 If you're on the same journey, let's connect! #DSA #CodingInterview #Python #LeetCode #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 5 — DSA with Python Solved the classic “Product of Array Except Self” problem today. This one introduced me to an important concept: 👉 Precomputation (Prefix & Suffix Pattern) Instead of recalculating products again and again, I learned how to: • Store prefix products (left side) • Store suffix products (right side) • Combine them to get the result efficiently 💡 Key Learning: Optimizing brute-force solutions using precomputation can significantly reduce time complexity. ⚡ What challenged me: Understanding how to manage two passes (left → right and right → left) without using extra space initially felt confusing — but breaking it step by step helped. 📈 Growth Insight: DSA is less about memorizing solutions and more about recognizing patterns like this one. On to Day 6 🔥 #DSA #Python #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Python Clarity Series - Episode 21 Topic : Modifying List While Iterating ⚠️ Dangerous mistake: Modifying a list while looping over it nums = [1, 2, 3, 4] for i in nums: if i % 2 == 0: nums.remove(i) print(nums) Output: [1, 3] ❗ (But logic can break in other cases) 👉 Problem: Loop skips elements because list is changing during iteration. 💡 Correct approach: nums = [1, 2, 3, 4] nums = [i for i in nums if i % 2 != 0] 💡 Rule: Never modify a list while iterating over it directly. This causes unpredictable bugs. #PythonPitfalls #CodingMistakes #StudentDevelopers
To view or add a comment, sign in
-
-
Day 23/100 – DSA Journey Problem: Remove Duplicates from Sorted Linked List A sorted linked list keeps duplicates next to each other, which makes it easy to remove them in one pass. Used simple traversal and pointer updates to skip duplicate nodes without extra space. Key Learning: Always use the structure of the data to simplify the solution. #Day23 #100DaysOfCode #DSA #LinkedList #Python #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 89 of #100DaysOfCode Solved LeetCode Problem 231 — Power of Two ✅ Cracked this one with a clean and efficient bit manipulation approach. The goal was to check whether a number is a power of two without using loops or recursion. 💡 Key Insight: A power of two has exactly one set bit in its binary form. So, using the trick: 👉 "n > 0 and (n & (n - 1)) == 0" This removes the lowest set bit — if the result is 0, it's a power of two. ⚡ Performance: • Runtime: 0 ms (Beats 100%) • Memory: 19.27 MB 🔍 What I learned: • Bit manipulation is insanely powerful • Writing optimal solutions matters • Small tricks can save big time Consistency > Motivation. On to Day 90 🔥 #LeetCode #DSA #CodingJourney #100DaysChallenge #BitManipulation #Python
To view or add a comment, sign in
-
-
While practicing DSA, I realized something: Solving problems randomly feels like progress… but it often leads to confusion. Things started making more sense when I began focusing on patterns instead of random questions. Here are some important list/array patterns to know: → Two Pointers. → Sliding Window. → Fast & Slow Pointer. → In-Place Reversal. → Merge Intervals. → Hash Map / Set. → Prefix Sum. → Monotonic Stack. Once you start recognizing patterns, problems feel more structured and easier to approach. Still learning and exploring these step by step. Comment down, Which pattern do you find easiest, and which one feels confusing? 📌 I share simple Python and DSA learnings here. #DSA #DataStructures #Algorithms #Programming #Python #CodingInterview #PythonDeveloper #SoftwareEngineer
To view or add a comment, sign in
-
-
🚀 Day 25 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem: Search a 2D Matrix (#74) 💡 Key Learning: This problem teaches how to apply binary search on a 2D matrix by treating it as a flattened sorted array. It’s all about visualizing the structure differently. ⚡ Approach: First apply binary search on rows to find the potential row Check range using first and last element of each row Once row is identified → apply binary search on that row Return true if target found, else false 🧠 Why this works: Matrix follows sorted properties row-wise and across rows Binary search efficiently reduces search space Achieves optimal time complexity → O(log(m × n)) 🔥 Result: ✔️ Runtime: 0 ms (Beats 100%) 📈 This is a classic problem combining matrix + binary search, frequently asked in interviews. A big thanks to Shivam Singh, Nikhil Yadav & Akshat Tiwari for this amazing challenge 🙌 Consistency is compounding. Keep going. 💪 #Day25 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #BinarySearch #Consistency
To view or add a comment, sign in
-
-
Day 118 Backtracking patterns are repeating — and getting clearer. #Day118 🧩 39. Combination Sum How today went: • Used index i to control choices • Two options at each step: → stay at i (reuse same element) → move to i + 1 (try next element) • Track current total • If total == target → store result • If total > target → backtrack What clicked: It’s all about: → controlling index → tracking total → backtracking at the right time Same pattern, more confidence. #LeetCode #DSA #Python #Backtracking #Recursion #LearningInPublic #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