🚀 50 Important Coding Questions – Question 44/50 🔹 Evaluate Reverse Polish Notation | LeetCode A classic Stack problem used to evaluate expressions written in postfix notation. 📌 Problem Statement You are given an array of strings tokens representing an arithmetic expression in Reverse Polish Notation (RPN). Evaluate the expression and return the result. Allowed operators: ➕ Addition ➖ Subtraction ✖ Multiplication ➗ Division Example: Input tokens = ["2","1","+","3","*"] Output 9 Explanation: (2 + 1) * 3 = 9 💡 Approach We use a stack to evaluate the expression. Algorithm: 1️⃣ Traverse the tokens array 2️⃣ If the token is a number → push it onto the stack 3️⃣ If the token is an operator • Pop two numbers from the stack • Apply the operation • Push the result back into the stack 4️⃣ The final stack element is the answer ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) 📌 LeetCode Result ✔ Accepted ⚡ Efficient stack-based solution 🧠 Concepts Strengthened ✔ Stack operations ✔ Expression evaluation ✔ Postfix (RPN) notation ✔ Arithmetic operation handling 📍 Question 44 of 50 in my “50 Important Coding Questions” series. Only 6 problems left to complete the challenge 💯 👉 Question 45 coming next! #DSA #LeetCode #Stack #Algorithms #CodingInterview #ProblemSolving #CPlusPlus #TechJourney
Reverse Polish Notation Evaluation with Stack
More Relevant Posts
-
🚀 Day 13 of My Coding Journey Today I worked on an interesting problem: 527 Valid Word Abbreviation 💡 👉 The challenge was to check whether a given abbreviation correctly represents a word. It involved handling: Character matching ✅ Skipping characters using numbers 🔢 Edge cases like leading zeros ❌ 💻 Key Logic I Used: Two pointers (i for word, j for abbreviation) If characters match → move both pointers If digit found → build number and skip characters in word If invalid case → return false ✨ Code Snippet: class Solution { public: bool validWordAbbreviation(string word, string abbr) { int i=0, j=0; while(i<word.size() && j<abbr.size()) { if(abbr[j]=='0') return false; if(word[i]==abbr[j]) { i++; j++; } else if(isalpha(abbr[j])) return false; else { int num=0; while(j<abbr.size() && isdigit(abbr[j])) { num = (num*10) + (abbr[j]-'0'); j++; } i += num; } } return i==word.size() && j==abbr.size(); } }; 🧠 What I Learned: How to efficiently parse strings with mixed characters & numbers Importance of handling edge cases like "01" ❗ Two-pointer technique is 🔥 for string problems 📌 Consistency > Perfection See you tomorrow with Day 14! 💪 #100DaysOfCode #DSA #Cpp #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
🚀 50 Important Coding Questions – Question 46/50 🔹 Decode String | LeetCode A classic Stack + String manipulation problem involving nested encoding patterns. 📌 Problem Statement Given an encoded string s, decode it using the rule: k[encoded_string] → repeat encoded_string k times The encoding may be nested. Example: Input s = "3[a2[c]]" Output "accaccacc" Explanation: a2[c] -> acc 3[acc] -> accaccacc 💡 Approach We use a stack to handle nested patterns. Steps: 1️⃣ Traverse the string 2️⃣ Push characters until ] is found 3️⃣ When ] appears: • Pop characters until [ → get substring • Extract the number (k) • Repeat the substring k times • Push back into stack 4️⃣ Continue until string ends 5️⃣ Build final result from stack ⏱ Time Complexity: O(n * k) (due to repeated strings) 📦 Space Complexity: O(n) 📌 LeetCode Result ✔ Accepted ⚡ Efficient stack-based decoding 🧠 Concepts Strengthened ✔ Stack for nested structures ✔ String parsing ✔ Handling multi-digit numbers ✔ Recursion-like behavior using stack 📍 Question 46 of 50 in my “50 Important Coding Questions” series. Only 4 problems left — final stretch! 💯🔥 👉 Question 47 coming next! #DSA #LeetCode #Stack #Strings #CodingInterview #ProblemSolving #CPlusPlus #TechJourney
To view or add a comment, sign in
-
-
Tired of huge conditional statements cluttering your code? 🤔 This week, let's talk about a common code smell: massive conditionals. They can make your code hard to read and maintain. By using polymorphism, we can simplify our logic and enhance readability. 🌟 In the before code snippet, we see a long chain of if-else statements. In the after snippet, we refactor the logic into separate classes, each handling its own behavior. This makes our code cleaner and more extendable! 💪 Have you faced similar issues? How do you handle massive conditionals? coding cleanarchitecture designpatterns csharp
To view or add a comment, sign in
-
-
Day 8/30 – Coding Streak Consistency is getting stronger day by day Today’s problem was about identifying whether a number is a power of two. Problem: Given an integer n, check if it can be written as: n = 2ˣ (for some integer x) Approach: I explored an optimized way using bit manipulation: • A power of 2 has only one set bit in its binary form • So, we can use: n & (n - 1) === 0 (for n > 0) Example: 1 → True (2⁰) 16 → True (2⁴) 3 → False What I learned today: • Basics of bit manipulation • Understanding binary representation of numbers • Writing more optimized solutions Every day = 1 step closer to becoming a better developer Let’s keep going Gravity Coding #Day8 #30DaysOfCode #CodingStreak #DSA #BitManipulation #ProblemSolving
To view or add a comment, sign in
-
-
Day 44 :-𝗘𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝗰𝘆 𝗶𝗻 𝗠𝗼𝘁𝗶𝗼𝗻: 𝗦𝗹𝗶𝗱𝗶𝗻𝗴 𝗪𝗶𝗻𝗱𝗼𝘄 𝗠𝗮𝘅𝗶𝗺𝘂𝗺 ⚡ Today’s DSA session was all about thinking beyond brute force. I worked on the Sliding Window Maximum problem on LeetCode — a classic that initially pushes you toward an O(n * k) approach, but rewards you heavily when you discover the right pattern. By applying the Monotonic Deque technique, I transformed the solution into an efficient linear-time algorithm. 🔹 𝗧𝗵𝗲 𝗧𝗲𝗰𝗵𝗻𝗶𝗰𝗮𝗹 𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝘀 🔸 Monotonic Deque Strategy Instead of recalculating the maximum for every window, I maintained a deque of indices in decreasing order of their values. 👉 This ensures the maximum element is always at the front. 🔸 Smart Pruning • Out-of-Window Removal: Indices that fall outside the current window are removed from the front. • Maintaining Order: Before inserting a new element, all smaller elements at the back are removed. 👉 Because they can never become the maximum in future windows. 🔸 Constant-Time Maximum Access With this structure, the maximum of each window is always available at peekFirst() → O(1) access. 🔹 𝗘𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝗰𝘆 ⚡ • Time Complexity → O(n) • Space Complexity → O(k) Each element is processed at most twice (added + removed), making the solution clean and optimal. 🔹 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 💡 👉 Optimization isn’t about doing more work faster — it’s about avoiding unnecessary work entirely. 👉 Choosing the right data structure (Deque here) can completely change the game. 🙏 Huge thanks to my mentors Anchal Sharma and Ikshit .. for their constant guidance and support. Their insights are helping me focus on patterns over brute force and stay consistent on this journey. #DSA #Java #100DaysOfCode #SlidingWindow #Deque #MonotonicQueue #ProblemSolving #Mentorship #LeetCode #SoftwareEngineering #CodingJourney 🚀
To view or add a comment, sign in
-
-
🚀 Day 27/60 — LeetCode Discipline Problem Solved: Length of Last Word Difficulty: Easy Today’s problem looked simple, yet it emphasized a subtle but important skill — handling edge cases cleanly. The goal was to find the length of the last word in a string, ignoring any trailing spaces. Instead of splitting the string or using extra space, the solution efficiently traverses from the end, skipping unnecessary characters and counting only what truly matters. It’s a reminder that strong coding is not always about complexity — sometimes, it’s about precision and clarity in small details. 💡 Focus Areas: • Practiced string traversal from end • Improved handling of trailing spaces • Reinforced clean and efficient logic • Avoided unnecessary extra space usage • Strengthened edge-case thinking ⚡ Performance Highlight: Achieved 0 ms runtime (100% performance). Small problems, when approached with discipline, sharpen the instincts that solve big ones. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #Strings #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Java #Developers #Consistency #TechJourney #LearnToCode
To view or add a comment, sign in
-
-
Wait, so my user agents write code for me, I cache certain things into a knowledge graph, and ocassionally ask for cross file refactoring, and ocassionally ask an agent to implement something new I've read about in a blog? And thats coding in 2026?
To view or add a comment, sign in
-
Claude Code has been taking notes on me. Build commands I use, mistakes it made, my coding patterns. Type /memory, then 'Open auto-memory folder'. Plain markdown files. It's been doing this automatically. It's called auto-memory. Claude writes notes to itself when it learns something useful. Next session, it loads them and doesn't repeat the same mistakes. /memory also shows your user memory (~/.claude/CLAUDE.md) and project memory (./CLAUDE.md). You write CLAUDE.md to guide Claude. Claude writes auto-memory to guide itself. Both load at session start, both are plain markdown you can edit. /memory to see it all.
To view or add a comment, sign in
-
Today I solved the “Single Number” problem on LeetCode 💻 🔹 Problem Statement:Given an array where every element appears twice except one, the task is to find that single element. 🔹 Approach Used:I solved this problem using the Bit Manipulation (XOR) technique.XOR has some important properties: a ⊕ a = 0 a ⊕ 0 = a So, when we take XOR of all elements in the array, the duplicate elements cancel out, leaving only the unique element 🔹 Code Idea:Iterate through the array and keep XOR-ing each element with a variable. The final value will be the answer. 🔹 Time Complexity: O(n)🔹 Space Complexity: O(1) 🚀 Key Takeaways: XOR-based problems are very common in coding interviews Optimized solutions are always better than brute-force approaches Understanding bit manipulation can greatly improve problem-solving skills Consistency is the key 🔥#LeetCode #DSA #CodingJourney #ProblemSolving # coding challenge🚀🚀
To view or add a comment, sign in
-
-
Half of my debugging session yesterday was caused by syntax errors. And I have to be honest about why. It was not a knowledge problem. I knew where the functions belonged. I understood what the variables did. I knew what each file was supposed to do in the stack. The problem was me. I am not as patient as I thought I was. I want to execute fast. Ship fast. Move to the next thing fast. And in that rush I was introducing mistakes that had nothing to do with understanding the code and everything to do with not slowing down long enough to write it properly. A missing bracket. A misspelled variable. A function called before it was defined. Small things. Expensive things. Because the time I saved rushing was nothing compared to the time I lost debugging errors I created myself. So I made three intentional decisions: 1. Slow down. Clean code takes slightly longer to write and significantly less time to fix. 2. Check once. Then check again. Before running anything. 3. Fully understand what a function or goal requires before writing a single line toward it. This is not a coding lesson. It is a discipline lesson wearing a coding jacket. The fastest way to ship is not to move faster. It is to make fewer mistakes. What is one small habit shift that has improved the quality of your work lately?
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