I begin my exploration of the #clanguage ctype functions with two of the most popular: toupper() and tolower(). These are also the only ctype functions that modify single characters. Bonus: I show one way to emulate these functions. Yes, it's the easy way. The hard way I do next week. https://lnkd.in/gsNAaw6e
Exploring ctype functions: toupper() and tolower() in C
More Relevant Posts
-
🚀 DSA Consistency Challenge – Day 76 Today’s focus was on Greedy Validation + String Simulation, where the real challenge wasn’t coding… but thinking in the right direction 🧠⚡ 🔴 1️⃣ Check if a Parentheses String Can Be Valid (Medium) 💡 Problem Twist: You’re allowed to change some characters — so instead of building the exact string, the real question is: 👉 Is it even possible to make it valid? 🧠 Approaches: 🔹 Brute Force Try all combinations for unlocked positions Validate each string ⛔ Exponential → Not practical 🔹 Stack-Based Approach Use stack for '(' and another for flexible indices Try to match ')' with available '(' or flexible positions Finally match remaining '(' with flexible positions (order matters!) ⏱️ O(n) time | O(n) space 🔹 Greedy (Optimal 💯) ✨ Key Insight: Validate instead of constructing Left → Right: Assume unlocked can act as '(' → Avoid excess ) Right → Left: Assume unlocked can act as ')' → Avoid excess ( 🔥 If both passes are valid → answer is TRUE ⏱️ O(n) time | O(1) space 🔴 2️⃣ Remove All Occurrences of a Substring (Medium) 💡 Core Idea: Removing a substring can create new occurrences → requires careful simulation 🧠 Approaches: 🔹 Brute Force (Find + Erase) Keep removing leftmost occurrence using find() ⛔ Inefficient due to repeated scanning ⏱️ O(n²) 🔹 Stack / String Simulation (Efficient ✅) Build result string step-by-step After each character: Check last m characters If match → remove instantly ✨ Works like a hidden stack ⏱️ O(n * m) | 🧠 O(n) 💭 Key Takeaways: Greedy isn’t always about max/min — sometimes it’s about validating feasibility Bidirectional traversal can simplify constraint-heavy problems Many string problems secretly use stack patterns Optimization often comes from avoiding repeated work
To view or add a comment, sign in
-
Recently, while revising sliding window problems, one thing became very clear: Sliding window is less about “moving a window” and more about maintaining the right state efficiently. In many array and string problems, the brute-force approach recalculates information for every subarray or substring, which quickly becomes expensive. The interesting shift happens when we stop recomputing and instead maintain information as the window expands or shrinks. This pattern appears in problems like: • Longest Repeating Character Replacement • Longest Substring Without Repeating Characters • Binary Subarrays With Sum • Count Number of Nice Subarrays What I found interesting is that implementation is usually not the hard part. The actual challenge is identifying: “What information should stay valid while the window moves?” Sometimes it’s: • Frequency counts of characters • Count of valid elements in a range • A condition that tells us when to expand or shrink the window Takeaway: Many O(n²) problems become O(n) once we stop recalculating information and start maintaining the right state efficiently. #DSA #Algorithms #ProblemSolving #Coding 🧠
To view or add a comment, sign in
-
Linked Lists may look simple. But mastering them builds strong pointer manipulation skills. 🚀 Here are the most important Linked List patterns every programmer should know: 📌 Core Techniques 1️⃣ Traversal Move node by node until NULL. 2️⃣ Fast & Slow Pointers Perfect for finding: • Middle Node • Cycle Detection • Palindrome Check 3️⃣ Reversal A must-know technique for many interview problems. 4️⃣ Dummy Node Makes insertion and deletion much cleaner. 5️⃣ Merge Two Lists The foundation of Merge Sort on Linked Lists. --- ⚡ Time Complexities Access by Index → O(n) Search → O(n) Insert at Head → O(1) Insert at Tail → O(1)* (with tail pointer) Delete at Head → O(1) Delete by Value → O(n) Reverse List → O(n) --- 🎯 Popular Interview Problems • Reverse Linked List • Middle of Linked List • Detect Cycle • Merge Two Sorted Lists • Remove Nth Node From End • Palindrome Linked List • Intersection of Two Lists --- 💡 Golden Rule Whenever you see: * "Middle" * "Cycle" * "Nth from End" Think Fast & Slow Pointers instantly. --- Master Linked Lists once, and half of your pointer problems become easy. #DataStructures #Algorithms #LinkedList #DSA #LeetCode #CodingInterview #Programming #SoftwareEngineer
To view or add a comment, sign in
-
Debugging is arguably the most underrated skill in tech. We've all been there: a simple script that refuses to work, or a feature behaving erratically. You've checked the logic a dozen times, and it should be right. Often, the culprit isn't a complex algorithm error, but something infuriatingly basic – a misplaced comma, an `==` instead of `=`, or a variable name typo. My go-to isn't immediately blaming the system; it's systematically questioning my assumptions. Break it down. Is the input what I expect? What's happening in this specific line? Often, a well-placed `print
To view or add a comment, sign in
-
Some algorithms just feel smart the moment you learn them. For me, it was the Difference Array Technique ⚡ Why? • Simple to implement • Easy to visualize • Extremely useful in contests Classic use case: You are given q queries of type [l, r, x] → Add x to every element from index l to r. Brute force works. But with large constraints? Too slow. Difference Array optimizes this beautifully using only boundary updates + prefix sums. Small idea. Huge optimization. Good LeetCode problems for this pattern 👇 • Car Pooling https://lnkd.in/gRviAhhA • Corporate Flight Bookings https://lnkd.in/gCUg6whZ • Shifting Letters II https://lnkd.in/g2SbPQT3 #DSA #Algorithms #LeetCode #CompetitiveProgramming
To view or add a comment, sign in
-
A clean way to solve LeetCode 76 — Minimum Window Substring — in O(N+M). Brute force tries every start-end pair, and for each window rescans the inside to check coverage. That's O(N²M) and you'll timeout immediately. There's a sharper move: maintain a live frequency map as you expand and shrink. Two counters — have and need — tell you in O(1) whether the window is valid: need = number of unique characters you must find in t have = how many of those unique characters you've actually satisfied in the current window A character is "satisfied" when its count in the window meets or exceeds its required count from t. The algorithm: Expand: slide the right pointer through s, adding each character to the window map. When a character just hits its required frequency, increment have. When have equals need, you've found a valid window. Now shrink. Shrink: while the window stays valid, record it if it's the smallest you've seen. Then move the left pointer inward to minimize. If shrinking removes something essential, have decrements and the window breaks. Go back to expanding, repeat until the end of s. Walked through the full algorithm visually on the example s="DAOBECODEBANCDNK", t="ABC" → answer="BANC". Visualizing the harder DSA problems I've worked through, one at a time. The sliding window pattern is foundational; once you lock it here, you can reuse it for longest substring without repeating, fruit into baskets, max consecutive ones, and dozens more. Full version (link in first comment). What's a pattern you wish was animated clearly? #dsa #algorithms #leetcode #softwareengineering #coding #slidingwindow #datastructures
To view or add a comment, sign in
-
We provide examples for the tools people already love 🧠🔌 Fastest way in is copy-paste that runs. Examples cover sklearn-style flows, Hugging Face, diffusers, LLMs/agents—pick what matches your stack. You bring the problem; wiring measurement in shouldn’t feel like a side quest. 🔁 Next step → Framework examples hub: https://lnkd.in/dKxngqmW
To view or add a comment, sign in
-
🧠 𝗕𝗲𝘁𝘄𝗲𝗲𝗻 𝘁𝗵𝗲 𝗕𝘆𝘁𝗲𝘀#15 ⚡ The Pointer vs Array Trap 💡 Your Weekly Monday Embedded Mystery Ever got confused between these two? int *a[]; int (*a)[]; They look similar… but behave completely differently. 🧪 What do they actually mean? 🔹 int *a[] 👉 Array of pointers to int. 🔹 int (*a)[] 👉 Pointer to an array of int ⚠️ Why this matters? Because this directly impacts: Memory layout Pointer arithmetic Function parameters Embedded data handling 🧠 Visual Thinking: 🔹 int *a[3] → a is an array with 3 elements → each element is a pointer to int 🔹 int (*a)[3] → a is a pointer → pointing to an array of 3 integers #BetweenTheBytes #CProgramming #Pointers #EmbeddedSystems #MemoryLayout #InterviewPrep #LowLevelProgramming
To view or add a comment, sign in
-
-
A lot of people find it intimidating, but I love DP. There's nothing quite like a bottom-up approach to systematically hit every single spot. Some people just want to use brute force, hammering away with no real strategy, and then they wonder why they have performance issues. But with DP, it's all about technique. You start slow and deeply explore all those overlapping areas. And when you hit the base for the last time without blowing your stack... man, there's just no better feeling than flawlessly executing Dynamic Programming to get an optimal solution. I find it easier to implement a top-down approach with recursion and memoization. Best for path finding algorithms or anything that needs to explore all paths.
To view or add a comment, sign in
-
-
𝗜𝗻𝘀𝘁𝗿𝘂𝗰𝘁𝗶𝗼𝗻𝘀 𝗮𝗿𝗲 𝗮 𝘄𝗶𝘀𝗵. 𝗛𝗼𝗼𝗸𝘀 𝗮𝗿𝗲 𝗮 𝗴𝘂𝗮𝗿𝗮𝗻𝘁𝗲𝗲. 𝗖𝗟𝗔𝗨𝗗𝗘.𝗺𝗱 tells Claude what you'd like to happen. Hooks make sure it happens, every single time, whether the model remembers or not. That distinction is the entire point of the system. 𝗕𝗲𝗳𝗼𝗿𝗲: "Always run prettier after editing." Add to CLAUDE.md. Cross your fingers. 𝗔𝗳𝘁𝗲𝗿: A `PostToolUse` hook with matcher `Edit|Write` runs prettier on the file. The model can't skip it. 𝗕𝗲𝗳𝗼𝗿𝗲: "Don't touch the .env file." Pray. 𝗔𝗳𝘁𝗲𝗿: A `PreToolUse` hook exits with code 2. The edit is blocked, and your stderr message is fed back to Claude as the reason. 𝗕𝗲𝗳𝗼𝗿𝗲: "Re-inject project conventions after compaction." Hope the summary kept it. 𝗔𝗳𝘁𝗲𝗿: A `SessionStart` hook with the `compact` matcher echoes whatever you want straight back into context. 𝗕𝗲𝗳𝗼𝗿𝗲: "Notify me when you need input." Watch the terminal. 𝗔𝗳𝘁𝗲𝗿: A `Notification` hook fires `osascript`. Desktop banner. Alt-tab away with confidence. Underneath all four examples sits the same machinery. Hooks fire deterministically at lifecycle points. Exit code 0 lets the action through. Exit 2 blocks it and turns your stderr into model feedback. JSON output unlocks finer control — allow, deny, ask, or rewrite the tool's input mid-flight. Matchers and the new `if` field decide which calls a hook even spawns for. Anything you keep reminding the agent to do is probably a hook waiting to be written. What's the one rule you keep repeating that should just be a hook? #ClaudeCode #Anthropic #AIEngineering #DeveloperTools #DevProductivity #AICoding #AgenticCoding
To view or add a comment, sign in