🧠 **C# Tricky Basic Question – Day 4** Let’s test your understanding of **floating-point behavior in C#**. ```csharp float f = 0f / 0f; Console.WriteLine(float.IsNaN(f)); ``` 💡 **What will be the output?** A) True B) False C) Compile Error D) Runtime Error Many developers expect a **runtime error** when dividing by zero… but floating-point numbers behave differently in C#. ⚡ Understanding concepts like **NaN (Not a Number)** is important when working with **numeric computations, data processing, and scientific calculations**. 👇 **Comment your answer before running the code.** I'll share the explanation in the comments. Follow for more **daily C# tricky questions** that sharpen your programming fundamentals. #CSharp #DotNet #Programming #CodingInterview #DeveloperCommunity #SoftwareDevelopment #Codi
C# Tricky Question: Floating-Point Behavior and NaN
More Relevant Posts
-
𝐃𝐚𝐲 𝟑𝟗 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding the minimum path sum in a triangle using Dynamic Programming. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Triangle 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Started from the last row of the triangle • Stored values in a DP array • Moved row by row upward • For each element, added the minimum of its two possible children Formula used: dp[col] = value + min(dp[col], dp[col + 1]) This bottom-up approach avoids recalculating subproblems. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Bottom-up DP simplifies many path problems • Only the next row is needed to compute the current row • Space optimization is possible by using a single array • Breaking a problem into smaller overlapping subproblems is the essence of DP 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n²) • Space: O(n) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Dynamic Programming often becomes easier when you start from the bottom and build your way up. 39 days consistent 🚀 On to Day 40. #DSA #Arrays #DynamicProgramming #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Today, I tackled a classic dynamic programming problem — Minimum Difficulty of a Job Schedule. This challenge really tested my understanding of: - Breaking problems into subproblems (partitioning jobs across days) - Optimizing brute force recursion using memoization - Thinking carefully about state definition (index, days left) Initially, I made a common mistake by trying to accumulate results greedily instead of exploring all valid partitions. Once I corrected that and properly defined the recurrence: 👉 current_day_max + solve(remaining_jobs, remaining_days) things started to click. Key takeaways include: - Always validate your recurrence before optimizing - DP is all about choosing the right state and transitions - Small indexing mistakes (i+1 vs ind+1) can completely break logic This was a valuable exercise in debugging and refining my dynamic programming approach. #LeetCode #DataStructures #Algorithms #DynamicProgramming #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 23/50 – LeetCode Challenge 🧩 Problem: Pascal’s Triangle Today’s problem focused on generating Pascal’s Triangle, a classic example that strengthens understanding of patterns and dynamic programming concepts. 📌 Problem Summary: Given an integer numRows, generate the first numRows of Pascal’s Triangle. Each element in the triangle is the sum of the two elements directly above it. Example: [1] [1,1] [1,2,1] [1,3,3,1] 🔍 Approach Used ✔ Started with the first row [1] ✔ For each new row: First and last elements are always 1 Middle elements = sum of two elements from previous row ✔ Built the triangle row by row ⏱ Time Complexity: O(n²) 📦 Space Complexity: O(n²) 💡 Key Learning ✔ Identifying patterns in problems ✔ Building solutions step by step ✔ Understanding dynamic programming intuition ✔ Working with nested loops effectively A simple problem that builds strong foundational thinking for more complex DP problems. Consistency is the key to improvement 🚀 🔗 Problem Link: https://lnkd.in/gjVfC6Kf #50DaysOfLeetCode #LeetCode #DSA #DynamicProgramming #Arrays #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
Most of us know that adding strings in a loop is a performance killer. Still, even a single line of concatenation can create a "terrifying abyss" of temporary objects and unnecessary memory allocations. I just published a deep dive on Medium about String Expressions—a technique that gives you JavaScript-level syntax with performance that beats manual reserve() and append() optimization. In this post: ✅ Why std::format isn't always the answer. ✅ The hidden cost of std::to_string. ✅ How the simstr library uses lazy evaluation to achieve 20% faster results than manual C++ code. #cpp #programming #algorithms
To view or add a comment, sign in
-
Day 77: 2D Prefix Sum Mastery 📊 Problem 3070: Count Submatrices with Top-Left Element and Sum Less Than k Today's challenge was a classic exercise in optimizing grid calculations. The goal: count how many submatrices starting from (0,0) have a total sum less than or equal to k. The Strategy: • 2D Prefix Sums: Instead of recalculating the sum for every possible submatrix, I used Dynamic Programming to build a prefix sum grid in-place. • The Formula: For any cell (i,j), the sum is the current value + the sum above + the sum to the left - the overlapping diagonal sum. • Efficient Counting: Since I only needed submatrices anchored at the top-left, a single pass through the grid was enough to compute the sums and increment the count. Using the Inclusion-Exclusion Principle turned an O(M² ⋅ N²) brute force into a crisp O(M ⋅ N) solution. One step closer to the goal. 🚀 #LeetCode #Java #Matrix #Algorithms #DataStructures #DailyCode
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟕𝟒/𝟑𝟔𝟓 🚀 📌 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐎𝐓𝐃: 𝐌𝐚𝐱𝐢𝐦𝐮𝐦 𝐀𝐦𝐨𝐮𝐧𝐭 𝐨𝐟 𝐌𝐨𝐧𝐞𝐲 𝐑𝐨𝐛𝐨𝐭 𝐂𝐚𝐧 𝐄𝐚𝐫𝐧 Continuing my 𝟑𝟔𝟓 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐂𝐨𝐝𝐞 journey with a focus on 𝐩𝐫𝐨𝐛𝐥𝐞𝐦-𝐬𝐨𝐥𝐯𝐢𝐧𝐠, 𝐃𝐒𝐀, 𝐚𝐧𝐝 𝐜𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲. 💪 🔎 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Use 3D Dynamic Programming where: dp[i][j][k] represents the maximum money at cell (i, j) using k special powers. At each step, either take the value normally or use a power to ignore negative coins. Transition from top and left cells. 🔍 𝐀𝐥𝐠𝐨𝐫𝐢𝐭𝐡𝐦 𝐮𝐬𝐞𝐝: Dynamic Programming with state (i, j, k). ⏱ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐦 × 𝐧 × 𝟑) 🧠 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐦 × 𝐧 × 𝟑) 📈 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲: When constraints allow limited special operations, include them as an extra DP dimension. #LeetCode #LeetCodeDaily #365DaysOfCode #DSA #Java #DynamicProgramming #Matrix #ProblemSolving #LearningInPublic 👨💻 🔗 Problem link in comments 👇
To view or add a comment, sign in
-
-
Panel Quantile Autoregressive Distributed Lag (PQARDL) estimation Use xtpqardl With (In) R Software https://dik.si/xtpqardl Panel Quantile Autoregressive Distributed Lag (PQARDL) estimation Use xtpqardl With STATA 19 https://ln.run/xtpqardl #rstudio #rsoftware #softwarer #stata #stata19 #olahdatasemarang #programming
To view or add a comment, sign in
-
🚀 Day 10 of 100 Days LeetCode Challenge Problem: Find All Possible Stable Binary Arrays II Today’s problem is an extension of Day 9—but with optimized Dynamic Programming ⚡ 💡 Key Insight: Same constraints: Fixed number of 0s and 1s No more than limit consecutive identical elements 👉 Which means: We must carefully control streak length And efficiently count all valid combinations 🔍 Approach (Optimized DP): Use DP + Prefix Sum Optimization State includes: Count of 0s used Count of 1s used Ending with 0 or 1 💡 Optimization: Instead of recalculating ranges repeatedly, use prefix sums This reduces time complexity significantly 👉 Apply modulo (10⁹ + 7) for large answers 🔥 What I Learned Today: Same problem can have multiple levels of optimization Prefix sum is powerful in reducing DP transitions Moving from brute → DP → optimized DP is real growth 📈 📈 Challenge Progress: Day 10/100 ✅ Double digits achieved! LeetCode, Dynamic Programming, Prefix Sum, Optimization, Combinatorics, Binary Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #DynamicProgramming #PrefixSum #Optimization #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟳𝟯/𝟭𝟬𝟬 — 𝗗𝗲𝗳𝘂𝘀𝗲 𝘁𝗵𝗲 𝗕𝗼𝗺𝗯 Day 73. Circular arrays with a twist. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟭𝟲𝟱𝟮: Defuse the Bomb (Easy) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Circular array. For each position, replace with the sum of the next k elements (if k > 0) or previous k elements (if k < 0). Example: code = [5,7,1,4], k = 3 → [12,10,16,13] The trick? Handling the circular nature with modulo. 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: For each position: k > 0: Sum next k elements using (j % n) k < 0: Sum previous k elements using ((j + n) % n) k = 0: All zeros The modulo handles wrapping around the array edges. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Handle k = 0 edge case (return all zeros) 👉 For k > 0: iterate forward with modulo 👉 For k < 0: iterate backward with modulo 👉 Build result array Time: O(n × k), Space: O(n) 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: Circular arrays appear everywhere: rotating logs, round-robin scheduling, cyclic buffers. Understanding modulo arithmetic for wrapping? Essential. 𝗖𝗼𝗱𝗲: https://lnkd.in/gxfZSvpN 𝗗𝗮𝘆 𝟳𝟯/𝟭𝟬𝟬 ✅ 𝟳𝟯 𝗱𝗼𝘄𝗻. 𝟮𝟳 𝘁𝗼 𝗴𝗼. #100DaysOfCode #LeetCode #Arrays #CircularArray #Algorithms #CodingInterview #Programming #Java #ModuloArithmetic #ProblemSolving
To view or add a comment, sign in
-
In light of Zig drawing eyes back to comptime (compile-time code execution), C23 and C++26 are adding #embed for compile-time file access! But what could you do before this new feature? Is it possible to embed file data into C++ scripts *without* having to convert it to valid C++ code manually or via some external tool? ⭐ Turns out, the answer is yes! Although not without its drawbacks... Check out my latest post to learn more about the bizarre power of C/C++ #include! https://lnkd.in/edP-J9u3
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
True