If your function signature is `handle(int s)`, you have zero type safety. `s` could be a status code, a user ID, or an age. The compiler can't tell the difference, allowing invalid values to cause chaos. The solution: "Enums". 🗸 An Enum is a unique data type with a fixed, named set of values. 🗸 Compile-Time Safety: The compiler flags errors if you use a value not on the list (e.g., trying to set a status to 99). 🗸 Data Modeling: Advanced enums (Rust/Python) hold data and enforce exhaustive pattern matching, preventing bugs when new states are added. Stop relying on brittle constants. Start using enums to enforce correct logic at compile time. https://lnkd.in/e6tnxzYP #CodingBestPractices #SoftwareEngineering #TypeSafety #Programming
Why Enums Improve Type Safety in Programming
More Relevant Posts
-
Top 10 common algorithms used in development: 1. Binary Search 2. Merge Sort 3. Quick Sort 4. Breadth-First/Depth-First Search 5. Dijkstra Shortest Path 6. Floyd-Warshall All-Source Shortest Path 7. Dynamic Programming (Knapsack) 8. Union-Find 9. Topological Sort 10. KMP String Matching Have you learned all of these?
To view or add a comment, sign in
-
-
: 🚀 DSA Progress – Day 86 ✅ Problem #213: House Robber II 🧠 Difficulty: Medium | Topics: Dynamic Programming, Recursion, Array 🔍 Approach: Extended the linear House Robber I problem to handle a circular arrangement of houses, where the first and last houses are adjacent. To solve this, I used Recursion + Memoization (Top-Down DP) and split the problem into two independent linear cases: Step 1 (Circular Constraint Handling): Since the first and last houses cannot be robbed together, divide the problem into two cases: Case 1 → Rob houses from index 0 to n-2 (exclude last). Case 2 → Rob houses from index 1 to n-1 (exclude first). Step 2 (Recursive Relation): For each index i, you have two options: Steal: nums[i] + solve(i+2) Skip: solve(i+1) Take the maximum of both. Step 3 (Memoization): Used a DP array to store results of subproblems to avoid redundant recursion. Step 4 (Final Answer): Take the maximum result from both cases — that’s the optimal amount that can be robbed without alerting the police. 🕒 Time Complexity: O(n) — Each index computed once per case. 💾 Space Complexity: O(n) — For recursion stack and DP array. 📁 File: https://lnkd.in/gkkfySt9 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem reinforced how to transform circular DP problems into linear ones by breaking dependencies. It also deepened my understanding of recursion + memoization and how DP elegantly handles overlapping subproblems. It’s a smart extension of House Robber I — showing how a small constraint (circularity) can change the entire problem structure. ✅ Day 86 complete — successfully looted the circle of houses without tripping a single alarm! 💰🏠🔄✨ #LeetCode #DSA #DynamicProgramming #Recursion #HouseRobber #Python #Memoization #100DaysOfCode #DailyCoding #InterviewPrep #GitHubJourney
To view or add a comment, sign in
-
🔥 Day 25/100 of #100DaysOfCode Problem: Longest Common Prefix - Find the longest common prefix string amongst an array of strings. Solution: Used a clever sorting approach! By sorting the array lexicographically, the longest common prefix must be between the first and last strings in the sorted array. Then compared characters position by position until finding a mismatch. Key Insight: After sorting, the first and last strings represent the lexicographic extremes - any common prefix across ALL strings must be common between these two extremes! Result: O(n log n) time complexity due to sorting, but very clean and intuitive implementation using StringBuilder for efficient string building. Smart algorithmic thinking beats brute force every time! 💡 #100DaysOfCode #LeetCode #Java #Algorithms #StringManipulation #Coding #Programming
To view or add a comment, sign in
-
-
🚀 Day 46 of #100DaysOfCode Problem: 3186. Maximum Total Damage With Spell Casting Difficulty: Medium Today’s challenge was about maximizing the total spell damage a magician can deal while following a tricky constraint — casting one spell blocks nearby damage values (power[i] - 2 to power[i] + 2). I used a Dynamic Programming + Binary Search approach to optimize the selection of non-conflicting spells. The bisect_right() method helped efficiently find compatible damage values, boosting runtime performance. 💡 Key Takeaways: Smart frequency mapping with Counter reduces redundancy Binary search (bisect_right) drastically improves DP efficiency Problem resembles “House Robber” with custom gaps in selection ✅ Result: Runtime: 496 ms — Beats 63.50% Memory: 39.97 MB — Beats 76.25% #LeetCode #Python #DynamicProgramming #100DaysOfCode #ProblemSolving #CodingJourney #Tech
To view or add a comment, sign in
-
-
🔥 Day 105 of 160 – GeeksforGeeks #gfg160 DSA Challenge 🔥 🎯 Problem: Get Min from Stack 🧠 Approach: This was a fantastic design problem! I implemented a special stack that returns the minimum element in O(1) time complexity without using an auxiliary stack. The key was a mathematical trick using a single variable minEle to track the current minimum. When pushing a new element x that is smaller than minEle, I didn't push x directly. Instead, I pushed a derived value (2 * x - minEle). This special value acts as a flag, and during a pop operation, it allows me to restore the previous minimum value using the formula prev_minEle = 2 * minEle - popped_value. This method cleverly maintains all required information with O(1) extra space. ✅ 1112 / 1112 test cases passed ⚡ Accuracy: 100% 🏆 Points Scored: 4 / 4 🕒 Execution Time: 0.05s 🔑 Key Learning: This problem is a classic example of augmenting a data structure's functionality. The mathematical encoding trick is a brilliant way to optimize for space, trading a bit of computational complexity during push/pop for a highly efficient getMin() operation. It highlights that sometimes, the values you store don't have to be the literal data. 💪 Progress Update: Day 105 is in the books! A tricky but very satisfying problem to solve. The consistency continues! 🚀 Next ➡️ Day 106 - Postfix Evaluation #Day105 #GeeksforGeeks #gfg160 #DSA #CodingChallenge #Python #ProblemSolving #Stack #DataStructureDesign #100DaysOfCode #Programmer
To view or add a comment, sign in
-
-
🚀Day 56 of #100DaysOfCode 🚀Solved LeetCode Problem 3347 – Maximum Frequency of an Element After Performing Operations II (Hard) This problem tested efficient use of sorting + sliding window technique to maximize element frequency after limited operations. The challenge was to determine how far we can extend a subarray where values can be adjusted within a range [-k, k] using at most num Operations modifications — achieving an optimized O(n log n) approach. Runtime: 266 ms — Beats 98.39% Memory: 31.96 MB — Beats 95.16% Key Concepts: Sorting for value proximity alignment Two-pointer technique for maintaining valid operation windows Cumulative operation cost calculation to ensure feasibility Feeling great to see consistent performance improvements and algorithmic clarity growing day by day! 🚀 #LeetCode #100DaysOfCode #Python #ProblemSolving #DataStructures #Algorithms
To view or add a comment, sign in
-
-
Today I Learned: Basics of Dynamic Programming 🚀 Dynamic Programming (DP) is a technique to solve problems by breaking them into smaller subproblems, solving each once, and reusing the results. The two key properties I learned today are: Optimal Substructure → the solution to a big problem can be built from smaller problems. Overlapping Subproblems → the same subproblems repeat, so we store results instead of recalculating. I also explored the two main approaches: Memoization (Top-Down) → solve using recursion + cache. Tabulation (Bottom-Up) → build solutions iteratively using a table. A simple example was the Fibonacci sequence, where DP reduces exponential time to linear time by storing previous results. Tomorrow’s Plan 📅: Practice problems like Climbing Stairs, Coin Change, and Longest Common Subsequence to strengthen my DP understanding. #DynamicProgramming #ProblemSolving #Coding #LearningJourney
To view or add a comment, sign in
-
Week 5 – Section 2 Completed! Built WOLF — a lightweight Python CLI network port scanner for authorized reconnaissance and lab use. Focus was on practicality and usability: multithreaded TCP scans, flexible port/target inputs (single, ranges, CIDR), configurable timeouts/threads, CSV output for automation, and optional PDF reports for sharing results. What I delivered: clear CLI UX, safe defaults, fast concurrent scanning, and polished export options — all in a minimal, easy-to-review repo. Great hands-on experience in Python networking, concurrency, and tool design. #Python #DevTools #Networking #SecurityTools #WOLF #LearningByDoing NUEXUS Technologies https://lnkd.in/dF6qNp3F
To view or add a comment, sign in
-
🚀 DSA Progress – Day 85 ✅ Problem #198: House Robber 🧠 Difficulty: Medium | Topics: Dynamic Programming, Recursion, Memoization 🔍 Approach: Used top-down dynamic programming (recursion + memoization) to find the maximum money that can be robbed without triggering alarms (i.e., without robbing adjacent houses). Step 1 (Recursion): At each index, you have two choices — Steal: Take the current house’s money and skip the next one (idx + 2). Skip: Move to the next house (idx + 1). Step 2 (Memoization): Store the result of each index in a dp array to avoid recalculating overlapping subproblems. Step 3 (Base Case): If the index goes beyond the number of houses, return 0 (no money to rob). Step 4 (Return Max): At each step, take the maximum of steal and skip. This ensures that you always choose the optimal set of non-adjacent houses to rob for maximum profit. 🕒 Time Complexity: O(n) — each house is processed once. 💾 Space Complexity: O(n) — for the dp array and recursion stack. 📁 File: https://lnkd.in/gy7gYyWA 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem strengthened my understanding of recursion with memoization. It showed how overlapping subproblems can be efficiently handled using DP. Also, it’s a great stepping stone toward advanced DP problems like House Robber II and Paint House. ✅ Day 85 complete — broke into every alternate house, but smartly! 💰🏠😎 #LeetCode #DSA #Python #DynamicProgramming #Recursion #Memoization #InterviewPrep #100DaysOfCode #DailyCoding #GitHubJourney
To view or add a comment, sign in
-
✅ Day 128 – GeeksforGeeks 160 Days of DSA Challenge Hi everyone, Today’s challenge was Total Decoding Messages — a classic Dynamic Programming problem based on string decoding and combinatorial counting. 🧩 Problem: A numeric string digits represents an encoded message where 'A' -> 1, 'B' -> 2, … 'Z' -> 26. The task is to determine how many possible ways the string can be decoded into letters. For example, "123" can be decoded as "ABC", "LC", or "AW", giving 3 possible decodings. 💡 Logic: We use a DP array dp[i] representing the number of ways to decode up to the i-th digit: If the current digit is not '0', it can stand alone → add dp[i-1]. If the last two digits form a number between 10 and 26, they can form a valid letter → add dp[i-2]. Base cases: dp[0] = dp[1] = 1 (a single non-zero digit has one decoding). This approach ensures O(n) time complexity with O(n) space — an elegant DP solution handling all edge cases like leading zeros or invalid pairs. #GeekStreak2025 #GFG160 #DSA #DynamicProgramming #ProblemSolving #StringDecoding #CodingChallenge #Python
To view or add a comment, sign in
-