𝗗𝗮𝘆 𝟲𝟲/𝟭𝟬𝟬 — 𝗘𝘃𝗮𝗹𝘂𝗮𝘁𝗲 𝗥𝗲𝘃𝗲𝗿𝘀𝗲 𝗣𝗼𝗹𝗶𝘀𝗵 𝗡𝗼𝘁𝗮𝘁𝗶𝗼𝗻 Day 66. Two-thirds done. Today's problem? The reason calculators exist. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟭𝟱𝟬: Evaluate Reverse Polish Notation (Medium) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: Evaluate expressions in Reverse Polish Notation (RPN). Numbers come first, operators after. Example: ["2","1","+","3","*"] → ((2+1)*3) = 9 No parentheses needed. No order of operations confusion. Just read left to right. 𝗧𝗵𝗲 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: Stack. When you see a number, push it. When you see an operator, pop two numbers, apply the operation, push the result. The last number standing? That's your answer. Used ArrayList as a stack for cleaner syntax with removeLast(). Same LIFO behavior. 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: This is how calculators and compilers evaluate expressions internally. RPN eliminates ambiguity. "3 + 4 * 5" needs rules. "3 4 5 * +" doesn't. Understanding this makes you understand how expression parsing works. 𝗖𝗼𝗱𝗲: https://lnkd.in/gXwcqVdP 𝗗𝗮𝘆 𝟲𝟲/𝟭𝟬𝟬 ✅ 𝟲𝟲 𝗱𝗼𝘄𝗻. 𝟯𝟰 𝘁𝗼 𝗴𝗼. #100DaysOfCode #LeetCode #Stack #RPN #Algorithms #ExpressionEvaluation #CodingInterview #Programming #Java #MediumLevel #CompilerDesign
More Relevant Posts
-
Day 74/365 – Remove Duplicate Letters Problem: Given a string s, remove duplicate letters so that each letter appears once and the result is the smallest lexicographical order possible. Example: "bcabc" → "abc" "cbacdcbc" → "acdb" 💡 Key Idea Use a Monotonic Stack to maintain characters in lexicographically smallest order. We also track: • Last occurrence of each character • Whether a character is already used in the result 🧠 Approach 1️⃣ Record the last index of each character. 2️⃣ Traverse the string. 3️⃣ Skip characters already included. 4️⃣ While stack top is bigger than current character and it appears later again, remove it to get a smaller result. 5️⃣ Push current character into the stack. 📦 Key Logic while(!stack.isEmpty() && stack.peek() > c && lastIndex[stack.peek() - 'a'] > i) { visited[stack.pop() - 'a'] = false; } This ensures: Lexicographically smallest result Each character appears only once 📊 Complexity ⏱ Time: O(n) 📦 Space: O(1) (since only 26 letters) ✨ Key Learning This is a classic Monotonic Stack + Greedy problem. Pattern to remember: 👉 Remove previous larger elements if they appear again later. This pattern appears in problems like: Smallest Subsequence Remove K Digits Monotonic stack optimization problems #Day74 #365DaysOfCode #LeetCode #MonotonicStack #GreedyAlgorithm #DataStructures #Algorithms #Java #DSA #CodingInterview
To view or add a comment, sign in
-
-
Day 72: Binary Search Squared 🏔️ Problem 3296: Minimum Number of Seconds to Make Mountain Height Zero Today’s problem was a masterclass in optimization. The goal: reduce a mountain's height to zero using workers who take progressively more time for each unit of height they remove. The Strategy: • Binary Search on Answer: Since the time needed is monotonic, I used binary search to find the minimum seconds required to finish the job. • Nested Binary Search: Inside that loop, I ran a second binary search for each worker to calculate the maximum height they could handle within that time limit. • Efficiency: This "Double Binary Search" approach kept the runtime lean even with a massive search space up to 10^16. Solving a "Binary Search inside a Binary Search" problem is a great way to test your grip on time complexity. It’s all about finding that optimal boundary. 🚀 #LeetCode #Java #BinarySearch #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐇𝐚𝐫𝐝 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝: 𝐅𝐢𝐧𝐝 𝐭𝐡𝐞 𝐒𝐭𝐫𝐢𝐧𝐠 𝐰𝐢𝐭𝐡 𝐋𝐂𝐏 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 :https://lnkd.in/gPQ5WExk 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 : https://lnkd.in/gYpvYnaW Today I worked on an interesting 𝐡𝐚𝐫𝐝 𝐩𝐫𝐨𝐛𝐥𝐞𝐦: 𝐅𝐢𝐧𝐝 𝐭𝐡𝐞 𝐒𝐭𝐫𝐢𝐧𝐠 𝐰𝐢𝐭𝐡 𝐋𝐂𝐏. The problem provides an 𝐋𝐂𝐏 (𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐂𝐨𝐦𝐦𝐨𝐧 𝐏𝐫𝐞𝐟𝐢𝐱) 𝐦𝐚𝐭𝐫𝐢𝐱 and asks us to construct the lexicographically smallest string that satisfies this matrix. 𝐊𝐞𝐲 𝐈𝐝𝐞𝐚 Instead of constructing substrings directly, the approach is: 1️⃣ Start assigning characters from 'a' onward. 2️⃣ If lcp[i][j] > 0, it means the substrings starting at i and j share the same first character. 3️⃣ Propagate the same character across positions where the LCP value indicates a match. 4️⃣ Finally, validate the entire LCP matrix using the rule: lcp[i][j] = (word[i] == word[j]) ? 1 + lcp[i+1][j+1] : 0 If any condition fails, no valid string exists. 𝐖𝐡𝐚𝐭 𝐈 𝐥𝐞𝐚𝐫𝐧𝐞𝐝 • How LCP matrices represent relationships between substrings • Constructing strings using greedy character assignment • Validating constraints using dynamic programming relations • Importance of verifying generated structures against given matrices Problems like this really sharpen string manipulation + matrix reasoning skills. Always fun pushing through Hard-level challenges! #LeetCode #DataStructures #Algorithms #CodingPractice #Java #ProblemSolving
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟲𝟴/𝟭𝟬𝟬 — 𝗧𝗶𝗺𝗲 𝗡𝗲𝗲𝗱𝗲𝗱 𝘁𝗼 𝗕𝘂𝘆 𝗧𝗶𝗰𝗸𝗲𝘁𝘀 🎟️ Day 68. Sometimes you don't need to simulate. You just need to think. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟮𝟬𝟳𝟯: Time Needed to Buy Tickets (Easy) 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: People in a queue buying tickets. Each person needs a certain number of tickets. They buy one at a time and go to the back of the line if they need more. How long until person k finishes buying? 𝗧𝗵𝗲 𝗜𝗻𝘀𝗶𝗴𝗵𝘁: You could simulate the queue. Or you could realize: People before position k contribute min(tickets[i], target) People after position k contribute min(tickets[i], target - 1) Why target - 1 for people after? Because person k finishes before they get another turn. No simulation needed. Just math. 𝗠𝘆 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻: One loop. For each person: If before or at position k: add min(tickets[i], tickets[k]) If after position k: add min(tickets[i], tickets[k] - 1) Sum it up. Done. Time: O(n), Space: O(1) 𝗪𝗵𝘆 𝗜𝘁 𝗠𝗮𝘁𝘁𝗲𝗿𝘀: The best solutions eliminate unnecessary work. Simulation is O(n × max(tickets)). Math is O(n). 𝗖𝗼𝗱𝗲: https://lnkd.in/gn58Hcf7 𝗗𝗮𝘆 𝟲𝟴/𝟭𝟬𝟬 ✅ 𝟲𝟴 𝗱𝗼𝘄𝗻. 𝟯𝟮 𝘁𝗼 𝗴𝗼. #100DaysOfCode #LeetCode #Queue #Algorithms #MathematicalThinking #CodingInterview #Programming #Java #Optimization #LogicalThinking
To view or add a comment, sign in
-
🚀 Day 88 of DSA Problem Solving 💡 Problem Solved: Two Sum II – Input Array Is Sorted 🔍 Problem Idea: Given a sorted array, find two numbers such that they add up to a target. Return their indices (1-based). 🧠 Key Learning: Instead of using HashMap (like in classic Two Sum), we can optimize using the **Two Pointer Approach** because the array is already sorted. ⚡ Concepts Practiced: * Two Pointer Technique * Array Traversal * Greedy Decision Making ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🚀 Approach: * Start with two pointers: one at the beginning and one at the end * If sum is too small → move left pointer forward * If sum is too large → move right pointer backward * If sum matches target → return indices 🔥 Real Journey Behind Solution: Initially, I thought of using HashMap (habit from Two Sum 😅), but then realized the sorted property is a huge advantage. Switching mindset to use **two pointers** made the solution cleaner and more optimal. This problem reminded me: 👉 Always look for constraints like “sorted” — they often unlock better solutions. 📌 Takeaway: Smart observation > brute force #Day88 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #TechGrowth #TwoPointers
To view or add a comment, sign in
-
-
Code Review Graph – 5x Fewer Tokens with Claude Code (MCP) Claude reads your entire codebase on every code review. 200 files. 150k tokens. Every. Single. Time. There's a smarter way — and it's a knowledge graph. `code-review-graph` is an open-source tool that builds a structural graph of your codebase using Tree-sitter, then gives Claude Code only what's actually relevant: → Changed files → Files in the blast radius (dependents, callers, importers) → Nothing else The result: ✅ 5–10x fewer tokens per review ✅ Automatic impact/blast-radius analysis ✅ Incremental updates in <2s after the first build ✅ Supports 12+ languages (Python, TS, Go, Rust, Java, C# and more) ✅ Native Claude Code integration via MCP The architecture is clean: Tree-sitter parses your code → SQLite + NetworkX stores the graph → Git diff detects what changed → MCP server exposes it to Claude. You get three review workflows out of the box: /code-review-graph:build-graph /code-review-graph:review-delta /code-review-graph:review-pr This is exactly the kind of tooling that makes AI-assisted development practical at scale — not just a demo, but a real workflow improvement. Have you thought about token costs in your AI dev workflow? Drop your approach below — I'd love to compare notes. #ClaudeCode #SystemDesign #MCP
To view or add a comment, sign in
-
-
Classical Backtracking Problem with a Classical Approach Solved Word Search (LeetCode 79) using a clean and intuitive DFS + Backtracking strategy Approach (Simple & Clear): •Start from every cell that matches the first character of the word. •Use DFS (Depth-First Search) to explore all 4 directions (up, down, left, right). •Mark the current cell as visited (by replacing it temporarily) to avoid revisiting. •If the full word is matched → return true immediately. •Backtrack by restoring the cell when the path doesn’t work. Key Insight: We explore all possible paths, but prune early when characters don’t match — this keeps the solution efficient. ⏱️ Time Complexity: 👉 O(m × n × 4^L) •m × n → starting points •4^L → exploring 4 directions for each character of length L 📌 Space Complexity: 👉 O(L) (recursion stack) 🔥 Clean recursion + smart backtracking = problem cracked! #DSA #Backtracking #LeetCode #CodingInterview #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day 94: Slanted Ciphertext & Loop Optimization 📟 Problem 2075: Decode the Slanted Ciphertext Today’s solve was a fun callback to the "ZigZag Conversion" problem I've tackled before. The challenge: read a string that was written diagonally across a matrix and then flattened into a single row. The Strategy: • Diagonal Traversal: The key is calculating the step size. In a slanted cipher, the next character in a diagonal is exactly columns + 1 indices away. • Refining the Loop: My first approach worked well, but I realized I could shave off execution time by adding an early exit. • The "Efficiency" Jump: By adding a simple check, if(j % column == column-1) break;—I stopped the inner loop from looking for diagonal neighbors that would logically fall outside the matrix boundaries. The Result: This small logic tweak dropped my runtime from 28ms down to 18ms, jumping from beating 56% to 97.63% of users. It’s a great reminder that even on "easier" problems, there’s always room to optimize. Seeing that performance graph move to the far left is the best kind of motivation. 🚀 #LeetCode #Java #StringManipulation #Algorithm #Optimization #DailyCode
To view or add a comment, sign in
-
-
𝗧𝗼𝗱𝗮𝘆’𝘀 𝗶𝗻𝘁𝗲𝗿𝗲𝘀𝘁𝗶𝗻𝗴 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: LeetCode 1980 – Find Unique Binary String Given n unique binary strings of length n, the task is to construct a binary string that does not exist in the list. The brute-force idea would explore up to (2^n) possibilities. But there’s a much cleaner insight: if we flip the i-th bit of the i-th string and build a new string from those flips, the result is guaranteed to differ from every string in the list. This technique comes from 𝗖𝗮𝗻𝘁𝗼𝗿’𝘀 𝗱𝗶𝗮𝗴𝗼𝗻𝗮𝗹 𝗮𝗿𝗴𝘂𝗺𝗲𝗻𝘁, a concept from mathematics that turns out to be surprisingly useful in algorithm design. Always enjoyable when a simple idea leads to an optimal 𝗢(𝗻) solution. #leetcode #algorithms #datastructures #problemSolving #softwareengineering #java
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