🚀 #100DaysOfCode – Day 15 | DSA Practice Continuing my 100 Days Data Structures and Algorithms challenge, today I solved an interesting problem based on numbers and digit manipulation. 📌 Problem: Check if The Number is Fascinating Given a 3-digit number n, we need to check whether it is fascinating or not. A number is called fascinating if: 👉 Concatenate n, 2*n, and 3*n 👉 The resulting number contains all digits from 1 to 9 exactly once 👉 It should not contain 0 Example: Input: n = 192 Concatenation → 192384576 Output → true 🧠 Approach / Logic: 1️⃣ Convert the numbers n, 2*n, and 3*n into strings and concatenate them. 2️⃣ Check if the total length of the string is 9. 3️⃣ Traverse the string and count the frequency of each digit. 4️⃣ If any digit is 0, return false. 5️⃣ Ensure each digit from 1 to 9 appears exactly once. 6️⃣ If all conditions are satisfied, the number is fascinating. 📊 Time Complexity: O(1) 📦 Space Complexity: O(1) 🎯 Key Learning: This problem highlights how string manipulation and frequency counting can be used to validate patterns in numbers. Consistency is the key to growth. Let’s keep improving every day! 💪 #100DaysOfCode #DSA #CodingJourney #ProblemSolving #CPP #LearningInPublic
100 Days of Code: Fascinating Number Checker
More Relevant Posts
-
🚀 #100DaysOfCode – Day 16 | DSA Practice Continuing my 100 Days Data Structures and Algorithms challenge, today I solved a popular problem based on arrays and two-pointer technique. 📌 Problem: Move Zeroes Given an integer array nums, move all 0’s to the end while maintaining the relative order of non-zero elements. The operation must be done in-place. Example: Input: nums = [0,1,0,3,12] Output → [1,3,12,0,0] 🧠 Approach / Logic: 1️⃣ Use two pointers: • i → to traverse the array • j → to track the position for non-zero elements 2️⃣ Traverse the array from left to right. 3️⃣ If the current element is non-zero, swap it with the element at index j. 4️⃣ Increment j to point to the next position. 5️⃣ Continue this process for the entire array. 6️⃣ At the end, all non-zero elements will be at the front, and all zeros will be shifted to the end. 📊 Time Complexity: O(n) 📦 Space Complexity: O(1) 🎯 Key Learning: This problem demonstrates how the two-pointer technique can efficiently solve in-place array problems while maintaining order. Consistency is the key to growth. Let’s keep improving every day! 💪 #100DaysOfCode #DSA #CodingJourney #ProblemSolving #CPP #LearningInPublic
To view or add a comment, sign in
-
-
Day 16/50 – DSA Challenge Today was about designing something smarter, not just solving. ->Min Stack This problem looks simple… until you realize: “getMin() must be O(1)” That’s where the real thinking starts. What I learned today: • Using an extra stack to track minimums is a design decision, not just coding • Every push/pop must maintain consistency between two stacks • This problem is less about loops and more about data structure design Key Insight: Good programmers solve problems. Better programmers design systems that make problems easier. ⚙️ From brute force → optimized → now smart data structure design That’s real progress. #DSA #LeetCode #DataStructures #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode – Day 17 | DSA Practice Continuing my 100 Days Data Structures and Algorithms challenge, today I solved a very important problem based on arrays and the Dutch National Flag Algorithm. 📌 Problem: Sort Colors Given an array nums containing only 0, 1, and 2, sort the array in-place so that all 0’s, 1’s, and 2’s are grouped together in order. Example: Input: nums = [2,0,2,1,1,0] Output → [0,0,1,1,2,2] 🧠 Approach / Logic: 1️⃣ Use three pointers: • low → for placing 0’s • mid → to traverse the array • high → for placing 2’s 2️⃣ Traverse the array while mid <= high. 3️⃣ If the current element is: • 0 → swap with low, move both low and mid forward • 1 → just move mid forward • 2 → swap with high, move high backward 4️⃣ Continue this process until the entire array is sorted. 📊 Time Complexity: O(n) 📦 Space Complexity: O(1) 🎯 Key Learning: This problem demonstrates the power of the Dutch National Flag Algorithm, which helps sort elements efficiently in a single pass without extra space. Consistency is the key to growth. Let’s keep improving every day! 💪 #100DaysOfCode #DSA #CodingJourney #ProblemSolving #CPP #LearningInPublic
To view or add a comment, sign in
-
-
🚀 New Article Drop: Master DSA Cheat Sheet – PART 04: Linked List I’ve just published Part 04 of my DSA Cheat Sheet series, and this one covers one of the most important data structures — Linked List. In this article, I’ve explained: What a linked list actually is (with a simple train analogy) 1) How nodes are connected 2) How to insert elements step by step 3) How to delete elements safely without breaking the structure I kept the explanation simple and practical so it’s easy to understand, especially if you’re just starting with DSA. If you're preparing for coding interviews or building your fundamentals, this one will help you a lot. Give it a read and let me know your thoughts. Feedback is always welcome 🙌 #DSA #LinkedList #Coding #Programming #InterviewPrep
To view or add a comment, sign in
-
💡 “In DSA, the beauty lies in finding simple formulas that solve complex patterns.” 🚀 #geekstreak60 — Day 45 Day 45 of the streak! Today’s problem was a perfect mix of bit manipulation and pattern recognition, introducing the elegant concept of Gray Code. 📌 Problem Statement Given an integer n, generate all binary strings of length n such that: ✅ Each successive string differs by exactly one bit ✅ The sequence starts from "0...0" 🧠 My Thought Process At first, generating all binary strings is easy — but ensuring that: Every consecutive pair differs by only one bit is the real challenge. Then I came across the key insight: 👉 Use the formula: gray = i ^ (i >> 1) This guarantees that each number differs from the previous one by only one bit. 🛠️ Optimized Approach ✅ Iterated from 0 to 2ⁿ - 1 ✅ Generated Gray code using bit manipulation ✅ Converted each number to binary string of length n ⚡ Complexity Analysis Time Complexity: O(2ⁿ × n) Space Complexity: O(2ⁿ) Efficient for n ≤ 16. 💡 Key Learning Bit manipulation can turn complex sequence constraints into simple mathematical expressions. Today strengthened my understanding of: ✅ Gray code generation ✅ Bitwise operations (^, >>) ✅ Pattern-based problem solving ✅ Writing efficient and elegant solutions Consistency continues strong 💪🔥 #geekstreak60 #npci #DSA #CPP #BitManipulation #ProblemSolving #CodingJourney #ContinuousLearning
To view or add a comment, sign in
-
-
💡 “In DSA, the hardest problems often become simple when you transform them into a familiar pattern.” 🚀 #geekstreak60 — Day 39 Day 39 of the streak! Today’s problem was a great example of how mathematical transformation + dynamic programming can simplify a complex problem. 📌 Problem Statement Given an array and an integer diff, the task was to count the number of ways to partition the array into two subsets such that: ➡️ Difference of subset sums = diff 🧠 My Thought Process At first, directly trying all partitions would be inefficient (exponential complexity). Then came the key transformation: Let: S1 = sum of subset 1 S2 = sum of subset 2 We know: S1 - S2 = diff S1 + S2 = totalSum Solving both: 👉 S1 = (totalSum + diff) / 2 🛠️ Optimized Approach The problem reduces to: ✅ Count number of subsets with sum = target Where: target = (totalSum + diff) / 2 Then applied Dynamic Programming (subset sum counting). ⚡ Complexity Analysis Time Complexity: O(n × target) Space Complexity: O(target) Efficient for given constraints. 💡 Key Learning Many DP problems become easier once you convert them into subset sum problems. Today strengthened my understanding of: ✅ Problem transformation techniques ✅ Subset sum DP ✅ Counting-based DP ✅ Optimizing exponential solutions Consistency continues strong 💪 #geekstreak60 #npci #DSA #CPP #DynamicProgramming #ProblemSolving #CodingJourney #ContinuousLearning
To view or add a comment, sign in
-
-
🚀 Day 114 of My DSA Problem Solving Journey - The Grind Continues! 🎉 After tackling some quick string manipulation yesterday, today I shifted gears to Stack data structures! I took on LeetCode's "Min Stack" (Medium) in C++. The Problem: We need to design a custom stack that supports the usual operations (push, pop, top) BUT with a catch—we also need to retrieve the minimum element in constant O(1) time! My Approach: The tricky part is figuring out how to get the minimum value instantly without scanning the entire stack. To achieve this, I used a classic Two-Stack Approach. 🧠 The Logic: Two Stacks: I initialized a main stack (st) to store all the elements and an auxiliary stack (minSt) specifically to keep track of the minimum values at any given point. Push Operation: When pushing a new value, it always goes into the main stack. If the minSt is empty, OR if the new value is less than or equal to the current minimum (the top element of minSt), I push it onto minSt as well. Pop Operation: When popping, I check if the element being removed from the main stack is exactly the same as the current minimum at the top of the auxiliary stack. If it matches, I pop it from both stacks! Otherwise, just pop from the main stack. Retrieving Min: Because of how we maintained the auxiliary stack, calling getMin() is as simple as returning the top value of minSt. Zero searching required! Takeaway: This problem is a brilliant example of a Space-Time Tradeoff. By sacrificing a little bit of memory to maintain a second stack, we successfully optimized our time complexity to a strict O(1) for every single operation! ⚡ Keep pushing! 💻🔥 #Day114 #CPP #Stack #LeetCode #DataStructures #Algorithms #DSA #ProblemSolving #CodingJourney #ContinuousLearning #REGexSoftwareServices
To view or add a comment, sign in
-
-
DSA session update — Trees completed! ✅ Trees are one of the most fundamental and powerful data structures in computer science. And now I understand why every serious DSA course spends so much time on them. Here is what I covered: 🔹 Binary Tree — Structure, nodes, root, leaf & height — Level order, inorder, preorder & postorder traversal 🔹 Binary Search Tree (BST) — Insertion, deletion & searching — Why BST gives O(log n) search 🔹 Tree Traversals — BFS — Breadth First Search — DFS — Depth First Search 🔹 AVL Tree & Balanced Trees — Why balance matters for performance What I realized — Trees are not just a data structure. They are a completely different way of thinking. Hierarchical thinking. Recursive thinking. And once you understand trees, so many other concepts in DSA start to make much more sense. Alhamdulillah for every concept that deepens the foundation. 🚀 #JavaScript #DSA #Trees #BinaryTree #BST #TreeTraversal #DataStructures #FrontEndDevelopment #InterviewPrep #LearningInPublic #CareerGrowth
To view or add a comment, sign in
-
-
You don’t struggle with DSA because it’s hard. You struggle because concepts and important problems are not structured in one place. Check out this structure Notes A clean structure covering core DSA topics: → Data Structure fundamentals → Arrays and key problems → Strings and important questions → Linked List concepts → Stack and Queue problems → Hashing topics → Dynamic Programming problems → Graph concepts and questions Simple to read Easy to follow See the full structure once Then start solving #DSA #SoftwareEngineering
To view or add a comment, sign in
-
Day 22 Today I solved “Missing Number” on LeetCode. The problem is to find the missing number from an array containing distinct numbers in the range [0, n]. At first, we might think of sorting or using a HashSet — but there’s a more elegant approach. 💡 Mathematical Approach (Gauss Formula) Idea: The sum of first n natural numbers = n(n+1)/2 Calculate expected sum Subtract actual sum of array The difference is the missing number Approach: Compute expected sum using formula Iterate through array to get actual sum Return the difference This gives: Time Complexity: O(n) Space Complexity: O(1) 💡 Key takeaway: Sometimes the best solution comes from mathematical observation, not data structures. #LeetCode #DSA #LearnInPublic
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