Day 67/100 — #100DaysOfCode Today , Worked on two problems: 𝐅𝐢𝐧𝐝𝐢𝐧𝐠 𝐦𝐢𝐧𝐢𝐦𝐮𝐦 𝐚𝐧𝐝 𝐦𝐚𝐱𝐢𝐦𝐮𝐦 𝐢𝐧 𝐚𝐧 𝐚𝐫𝐫𝐚𝐲 𝐅𝐢𝐧𝐝𝐢𝐧𝐠 𝐟𝐢𝐫𝐬𝐭 𝐚𝐧𝐝 𝐥𝐚𝐬𝐭 𝐨𝐜𝐜𝐮𝐫𝐫𝐞𝐧𝐜𝐞 𝐨𝐟 𝐚 𝐭𝐚𝐫𝐠𝐞𝐭 𝐢𝐧 𝐚 𝐬𝐨𝐫𝐭𝐞𝐝 𝐚𝐫𝐫𝐚𝐲 𝟏. 𝐌𝐢𝐧 & 𝐌𝐚𝐱 𝐢𝐧 𝐀𝐫𝐫𝐚𝐲(Brute Force clarity) At first glance, it’s simple — but the real learning was the mental model. Instead of guessing whether a number is min or max, I learned: Always keep a reference (minVal, maxVal) Compare every element with that reference Update accordingly Core idea: Don’t judge a number in isolation, compare it with what you already know. Time complexity: O(n) because every element must be seen. 𝟐. 𝐅𝐢𝐫𝐬𝐭 & 𝐋𝐚𝐬𝐭 𝐏𝐨𝐬𝐢𝐭𝐢𝐨𝐧 𝐨𝐟 𝐄𝐥𝐞𝐦𝐞𝐧𝐭 (Binary Search shift) My initial instinct was: Traverse array Maybe sort But that completely breaks the constraint. Since the array is already sorted and O(log n) is required, the correct approach is: Use Binary Search Not once, but twice: First occurrence → move left Last occurrence → move right Core idea: When sorted + fast search is required → think Binary Search, not loops. I’m starting to see a pattern: Problems are not about code first They are about choosing the right approach Wrong thinking → correct code won’t save you Right thinking → code becomes easy On to Day 68
Finding Min & Max in Array and First & Last Occurrence of Element
More Relevant Posts
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Today I solved "Path Sum III" on LeetCode using a DFS + Recursion approach. Key Idea: We need to count all paths where the sum of node values equals the target. The path doesn’t have to start from the root — it can start from any node! Approach: • For every node, treat it as a starting point • Use DFS to explore all downward paths • Reduce the target at each step (target - node->val) • If a node matches the remaining target → count it • Repeat the process for left and right subtrees Why this works: Every node gets a chance to act as the starting point, and DFS ensures we explore all possible paths efficiently. Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Backtracking (implicit) Time Complexity: O(n²) in worst case Space Complexity: O(h) This problem helped me understand how to explore all possible paths in a tree, not just root-based ones — a big step forward in mastering tree problems From single path problems → to handling multiple dynamic paths… growing every day #Day90 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
.Day 47 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Bracket Validity (Valid Parentheses) We were given a string s. It contains only brackets: (), {}, [] Task was to check whether the string is valid. Valid means: ✔️ Same type of brackets ✔️ Correct order ✔️ Every opening has a matching closing 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Traverse the string. 🔹️If opening bracket → push into stack. 🔹️If closing bracket: ▪️Check if stack is empty → invalid ▪️Check top of stack ▪️If matching → pop ▪️Else → invalid 🔹️At the end, stack should be empty. If empty → valid Else → not valid 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack is the best fit for bracket matching problems. ▫️Checking empty stack avoids runtime errors. ▫️Matching pairs logic must be handled carefully. ▫️Order of brackets is more important than count. Day 47 completed. Revising stack patterns again 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 17 / 100 Days of Code Challenge 💻🔥 Solved LeetCode 901 — Online Stock Span 📈 🔍 Problem • Design a system that calculates the stock span for each day • Span = number of consecutive days (including today) where price is less than or equal to today’s price ⚙️ Approach (Monotonic Stack) • Use a stack to store pairs of (price, span) • For each new price, remove all smaller or equal prices from the stack • Add their span to current span • Push the current price with updated span 💡 Key Learning • Strong understanding of monotonic stack pattern • Avoiding repeated comparisons using accumulated span • Optimizing from O(n²) to O(n) (amortized) ⏱ Complexity • Time: O(n) ⏳ • Space: O(n) 📦 Consistency continues 🚀 #100DaysOfCode #LeetCode #DSA #Stack #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 39 – #100DaysOfLeetCode Challenge Today I worked on the problem “Simplify Path.” Problem Overview: Given a string representing an absolute path in a Unix-style file system, the task is to simplify it and return the canonical path. Rules to follow: "." refers to the current directory (ignore it) ".." refers to the parent directory (go one step back) Multiple slashes "//" should be treated as a single slash The result must start with / and not end with a trailing slash Example: Input: path = "/a/./b/../../c/" Output: "/c" Approach – Stack-Based Simulation To solve this efficiently: 🔹 Split the path using / as delimiter 🔹 Use a stack to process directory names 🔹 Ignore empty strings and "." 🔹 When encountering "..", pop from stack (if not empty) 🔹 Otherwise, push valid directory names onto the stack 🔹 Finally, construct the canonical path from the stack Time Complexity: O(n) Space Complexity: O(n) Key Learning: This problem demonstrates how stacks can be used to simulate real-world systems like file navigation, helping manage hierarchical structures effectively. Day 39 of my #100DaysOfLeetCode journey staying consistent and building stronger problem-solving intuition every day!
To view or add a comment, sign in
-
-
Day 26/75 🚀 Solved Decode String (LeetCode 394) today! ✅ All 34/34 test cases passed ⚡ Runtime: 0 ms (Beats 100%) 💾 Memory: 8.22 MB (Beats ~99%) 🔍 Approach: Used a stack-based approach to decode the string. ✔️ Traverse the string character by character ✔️ If character is not ‘]’ → push into result ✔️ When ‘]’ is found: • Extract substring inside brackets • Get the number (repeat count) before '[' • Repeat the substring and append back This continues until the entire string is decoded. 💡 Key Learning: Whenever you see nested patterns (like brackets) → think of stack. It helps manage order and structure efficiently. Consistency + patience = clean solutions 💯 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 19/75 🚀 Solved LeetCode 724 — Find Pivot Index today! ✅ All 747/747 test cases passed ⚡ Runtime: 1 ms (Beats 25.74%) 💾 Memory: 35.78 MB (Beats 53.67%) 🔍 Approach — Prefix Sum Logic The goal is to find an index where the sum of elements to the left equals the sum of elements to the right. Here’s how I solved it: First compute the total sum of the array. Maintain a running left sum (currs). For each index: Left Sum = currs Right ends = sum - currs-nums[i]; If both are equal → we found the pivot index. Update currs by adding the current element. This solution runs in O(n) time and uses O(1) extra space. 💡 Key Learning: Prefix sums make array problems much easier. Whenever you need to compare left vs right portions, prefix sum is the perfect approach. Keep building consistency — one problem a day, every day 💪🔥 #LeetCode #LeetCode75 #CPP #DSA #SlidingWindow #ProblemSolving #CodingJourney #75DaysOfCode
To view or add a comment, sign in
-
-
1 in 3 edits Claude Code makes are now to files it hasn't read. That's from a telemetry analysis of 234,760 tool calls by a team shipping 191,000 lines of C and GPU driver code in a single weekend using Claude Code. Between February and April, they tracked: Reads per edit: 6.6 → 2.0. Reasoning loops per 1K calls: 8.2 → 26.6. User interrupts: up 12x. They built a stop hook to catch Claude quitting tasks early with phrases like "good stopping point." It fired 173 times in 17 days. Zero times before. The cause is a feature called adaptive thinking that Anthropic shipped on February 9. The model decides how long to reason per turn. On some turns it allocates zero. From Anthropic's own GitHub reply: "The specific turns where it fabricated (stripe API version, git SHA suffix, apt package list) had zero reasoning emitted, while the turns with deep reasoning were correct." The workaround is an environment variable: CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1. Or run /effort high in your sessions. If Claude Code has felt off lately, now you know why.
To view or add a comment, sign in
-
-
🔥 Day 173 of My LeetCode Journey Problem 113: Path Sum II 💡 Problem Insight: Today’s problem extends Path Sum — instead of just checking existence, you must return all root-to-leaf paths whose sum equals the target. This shift from a Boolean list makes the problem more complex. 🧠 Concept Highlight: The solution uses DFS + backtracking: Traverse the tree while maintaining the current path Subtract node values from the target sum When a valid leaf is reached, store the path Backtrack to explore other possibilities Backtracking is essential to avoid mixing paths. 💪 Key Takeaway: Whenever a problem asks for all possible paths/combinations, backtracking is the go-to technique. Managing state correctly is more important than traversal itself. ✨ Daily Reflection: This problem reinforced the need for discipline when storing results. Without proper backtracking, solutions become incorrect quickly. #Day173 #LeetCode #BinaryTree #DFS #Backtracking #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
1 in 3 edits Claude Code makes are now to files it hasn't read. That's from a telemetry analysis of 234,760 tool calls by a team shipping 191,000 lines of C and GPU driver code in a single weekend using Claude Code. Between February and April, they tracked: Reads per edit: 6.6 → 2.0. Reasoning loops per 1K calls: 8.2 → 26.6. User interrupts: up 12x. They built a stop hook to catch Claude quitting tasks early with phrases like "good stopping point." It fired 173 times in 17 days. Zero times before. The cause is a feature called adaptive thinking that Anthropic shipped on February 9. The model decides how long to reason per turn. On some turns it allocates zero. From Anthropic's own GitHub reply: "The specific turns where it fabricated (stripe API version, git SHA suffix, apt package list) had zero reasoning emitted, while the turns with deep reasoning were correct." The workaround is an environment variable: CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1. Or run /effort high in your sessions. If Claude Code has felt off lately, now you know why. I write about stuff like this every week in the newsletter. Link in profile.
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