Day 64/100: The "Special Binary String" Puzzle 🧩 Today's challenge was a fascinating problem that combines recursion with sorting logic - "Make Largest Special Binary String". At first glance, this problem seems deceptively simple. We're given a special binary string (defined recursively as a string that can be composed of smaller special strings concatenated together), and we need to rearrange it to form the lexicographically largest possible special string. The key insight? Special binary strings are essentially valid parentheses where '1' represents '(' and '0' represents ')'. This transforms the problem into finding valid parenthetical groupings and recursively optimizing them! My Approach: Track the balance of 1s and 0s while traversing the string Whenever the balance returns to zero, we've found a valid "special" substring Recursively process each inner substring Sort all special substrings in descending order and concatenate Wrap each processed result with '1' and '0' The trickiest part was understanding that each special substring needs to be transformed independently before sorting them at the current level. This ensures we're always working with the "largest" version at every nesting level. Runtime: 4ms (beats 15.40%) Memory: 43.13 MB (beats 79.62%) Learning to see binary strings as parentheses opened up a whole new perspective on this problem! Sometimes the hardest part isn't writing the code, but recognizing the pattern hiding in plain sight. 🔍 #100DaysOfCode #LeetCode #Java #CodingChallenge #Algorithms #ProblemSolving #Recursion #BinaryStrings #Programming #DeveloperJourney #CodeNewbie #TechCommunity #StringManipulation #DataStructures #Day64
Optimizing Special Binary Strings with Recursion
More Relevant Posts
-
🚀 Day 525 of #750DaysOfCode 🚀 💡 LeetCode 1980: Find Unique Binary String Today’s problem was an interesting one involving binary strings and a clever observation. We are given n unique binary strings of length n, and the task is to return any binary string of length n that does not exist in the given array. 🔎 Approach I Used I applied a concept similar to Diagonalization. Traverse the array from 0 → n-1 Look at the i-th character of the i-th string Flip it (0 → 1 or 1 → 0) Append the flipped character to build a new string This guarantees the newly created string differs from every string in the list at least at one position, ensuring it is unique and not present in the array. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) This approach works efficiently because the constraints are small and we only need to ensure one position difference with each string. Problems like this highlight how a simple observation can eliminate brute force completely. #leetcode #coding #programming #java #datastructures #algorithms #problemSolving #developer #codingchallenge #750DaysOfCode
To view or add a comment, sign in
-
-
Hi there 👋 Today I want to give you a small glimpse into the future of C++ and honestly, it’s pretty exciting. With static reflection in C++26, we can finally inspect our types and structs at compile time and do things that used to feel like magic in languages like Java or C#. But here’s the real twist: ⚡ No runtime reflection overhead ⚡ Everything happens at compile time ⚡ Zero runtime penalty Yes, compilation might take a little longer… but let’s be honest if you’re already using heavy templates, you’re probably used to that 😅 The power you get in return is incredible. As a small example, I wrote a tiny function that can print almost any struct automatically using our new friend std::meta. Of course, it’s a quick prototype and there are still edge cases I didn’t wrap in it but the idea is clear: 👉 We can inspect types 👉 Iterate over members at compile time 👉 Generate code based on structure And printing structs is just the beginning. If you watched my Python bindings talk at CppCon this year, you might already imagine where this is going… Reflection + C++ bindings = extremely powerful tooling. Think about: automatic bindings serialization schema generation logging / debugging tools meta-driven frameworks The number of possibilities here is huge. Personally, I can’t wait to start using this in production. C++ keeps evolving, and features like this show that the language is still pushing forward in powerful ways. ⚙️ What would YOU build first with C++ static reflection? #cpp #cpp26 #programming #softwareengineering #reflection
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟳𝟰/𝟭𝟬𝟬 — 𝗠𝗮𝘅𝗶𝗺𝘂𝗺 𝗘𝗿𝗮𝘀𝘂𝗿𝗲 𝗩𝗮𝗹𝘂𝗲 Day 74. Sliding window + hash set. Two patterns, one problem. This is how you level up. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟭𝟲𝟵𝟱: Maximum Erasure Value (Medium) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Find the maximum sum of a subarray with all unique elements. Can't just find max sum. Can't just find unique elements. Need both. 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: Sliding window + hash set. Expand window by moving end. When you hit a duplicate: Shrink from start until duplicate is removed Track sum and uniqueness simultaneously The hash set ensures uniqueness. The sliding window finds the maximum. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Two pointers: start and end 👉 HashSet tracks seen elements 👉 While duplicate exists: remove from start, shrink window 👉 Add current element, update sum 👉 Track maximum sum Time: O(n), Space: O(n) 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: Combining patterns is the real skill. Sliding window alone isn't enough. Hash set alone isn't enough. Together? They solve it. 𝗖𝗼𝗱𝗲: https://lnkd.in/gU3xzr_H 𝗗𝗮𝘆 𝟳𝟰/𝟭𝟬𝟬 ✅ 𝟳𝟰 𝗱𝗼𝘄𝗻. 𝟮𝟲 𝘁𝗼 𝗴𝗼. #100DaysOfCode #LeetCode #SlidingWindow #HashSet #Algorithms #TwoPointer #CodingInterview #Programming #Java #MediumLevel #PatternCombination
To view or add a comment, sign in
-
🎯 Day 68 of #100DaysOfCode 📌 Problem: Combination Sum II Today's challenge was a twist on the classic combination sum problem! Each number in candidates can only be used once, and the solution set must not contain duplicate combinations. 🧠 Approach: Sorted the array first to handle duplicates efficiently Used recursion with backtracking Skipped duplicate elements to avoid repeated combinations Explored all possible combinations by picking/unpicking elements 📊 Stats: ✅ 176/176 test cases passed ⚡ Runtime: 6 ms | Beats 73.38% 💾 Memory: 45.61 MB | Beats 19.56% 📝 Takeaway: The key challenge was avoiding duplicate combinations while ensuring each element is used at most once. Sorting + skipping duplicates during recursion made this elegant. Memory optimization is the next frontier! 🔗 Problem: Combination Sum II 🏷️ #LeetCode #CodingChallenge #Java #Backtracking #Recursion #Algorithms #DuplicateHandling #TechJourney #Programming
To view or add a comment, sign in
-
-
Weekend deep dive into floating-point representation 👨💻 I wrote a blog breaking down how 42.75 is stored in memory across JavaScript, C++, Java, and Python using IEEE-754: ✔ Binary conversion ✔ Normalization ✔ Exponent bias ✔ 32-bit vs 64-bit comparison ✔ Raw memory layout ✔ Floating-point precision issues It’s always interesting how something as simple as a number hides so much complexity. Read here: 👉https://lnkd.in/d-w8ZNrt Feedback welcome! #LowLevel #SystemsProgramming #IEEE754 #Backend #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 535 of #750DaysOfCode 🚀 ✅ Solved: Count Submatrices with Top-Left Element and Sum ≤ k (LeetCode 3070) Today’s problem was a great example of using 2D Prefix Sum to optimize matrix queries. Instead of checking every possible submatrix, we can observe that the question only allows submatrices that include the top-left element (0,0). This means every valid submatrix is just a prefix rectangle, so we can compute the sum efficiently using prefix sums. 💡 Key Learning: Used 2D Prefix Sum technique Reduced brute force complexity to O(m × n) Learned how to handle matrix range sum problems efficiently 📌 Approach: Build prefix sum for each cell Check if sum from (0,0) to (i,j) ≤ k Count valid submatrices This problem improved my understanding of: ✔️ Prefix Sum ✔️ Matrix DP patterns ✔️ Optimization from brute force to efficient solution Consistency continues 🔥 On to Day 536 tomorrow. #leetcode #java #datastructures #algorithms #codingchallenge #prefixsum #matrix #programming #softwareengineering #750daysofcode
To view or add a comment, sign in
-
-
🚀100 Days of Code - Day 10 Today I worked on a classic Regular Expression Matching problem. Given a string s and a pattern p, determine if the entire string matches the pattern. The pattern supports: • . → matches any single character • * → matches zero or more of the preceding element Example: s = "ab" p = ".*" Output → true This problem is a great exercise in Dynamic Programming and pattern matching concepts. #Java #Algorithms #DataStructures #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
🚫 Null pointers caused Tony Hoare to call it his "billion-dollar mistake." But in 2026, Rust developers are still solving this problem the smart way: by simply not allowing null. Instead of a silent `null` that crashes your app at runtime, Rust forces you to handle the absence of a value explicitly at compile time using the `Option<T>` type. 🛑 The Problem with Null In languages like Java or C#, a variable can be `null` without you knowing. Accessing it leads to a `NullPointerException` or a crash. It’s a silent killer of production systems. ✅ The Rust Solution: Option<T> Rust replaces `null` with an enum that has two states: • `Some(T)`: A value exists. • `None`: No value exists. The compiler *forces* you to handle both cases. You literally cannot compile code that ignores the possibility of `None`. 💻 Code Example Let's look at a function that finds a user by ID. In a traditional language, it might return `null`. In Rust: `fn find_user(id: u32) -> Option<String> {` ` if id == 1 { Some("Alice".to_string()) }` ` else { None }` `}` Notice the return type is `Option<String>`, not `String`. The caller *must* handle the `None` case: `match find_user(2) {` ` Some(name) => println!("User: {}", name),` ` None => println!("User not found!"),` `}` No runtime surprises. No crashes. Just safe, explicit code. 🚀 Why This Matters • Eliminates an entire class of runtime errors. • Makes intent clear in your type signatures. • Leverages the compiler as a safety net. Stop guessing if a value exists. Start knowing. #RustLang #SoftwareEngineering #NullSafety #Programming #CodeQuality #TechTrends2026 RustLang,SoftwareEngineering,NullSafety,Programming,CodeQuality,TechTrends2026 What's your favorite language feature that prevents bugs? Let me know in the comments! 👇
To view or add a comment, sign in
-
Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
To view or add a comment, sign in
-
-
Day 3 of the DSA Partner Challenge. 🔥 Keeping it light today. Loops. Conditionals. The two things that make your code actually do something. 10 practice problems — all geometry formulas. Simple inputs, clean outputs. Perfect for getting comfortable with syntax before the harder stuff starts. Notes + problems in the repo 👇 📂 https://lnkd.in/g2yF6JAb 💬 Community → https://lnkd.in/g57zJcsJ 📸 https://lnkd.in/gajv9hE4 #DSAChallenge #DSA #Java #Python #CPlusPlus #LeetCode #Loops #Conditionals #Programming #100DaysOfCode #CodingCommunity
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