LeetCode 90-Day Challenge – Day 74 Problem: Evaluate Reverse Polish Notation Difficulty: Medium Problem: We’re given an array of strings tokens that represent an arithmetic expression in Reverse Polish Notation (RPN). Our goal is to evaluate this expression and return the result as an integer. In RPN, the operator appears after its operands, for example, instead of writing (2 + 1) * 3, we write 2 1 + 3 *. Solution approach: I solved this using a stack-based approach. Each time we encounter a number, we push it to the stack. When we encounter an operator, we pop the top two numbers, perform the operation, and push the result back. In the end, the stack will contain a single number, the final evaluated result. This approach runs in O(n) time and ensures integer division truncates toward zero, as required by the problem. #LeetCode #90DaysOfCode #Python #LinkedInChallenge #CodingJourney #ProblemSolving #LeetCodeChallenge
Evaluating Reverse Polish Notation with a Stack
More Relevant Posts
-
🚀 Day 32 DSA Challenge – Problem #14: Longest Common Prefix Finding unity in diversity — even among strings 😄✨ 🎯 Problem Statement: Given an array of strings, return the longest common prefix shared among them. If there’s no common prefix, return an empty string "". 🧠 How I Solved It: Started by assuming the first string as the initial prefix. Iterated through each subsequent string, trimming the prefix until it matched the start of the current word. Used Python’s startswith() to efficiently check prefix matches. Stopped early if the prefix became empty — ensuring optimal performance. ⚙️ Performance Stats: ⏱ Runtime: 0ms (beats 100%) 💾 Memory: 12.52MB (beats 27.15%) ✅ Testcases Passed: 126 / 126 💡 What I Learned: This problem reinforced the value of incremental reduction and early termination in string algorithms. Sometimes, solving efficiently means knowing when to stop ⏳💬 #LeetCode #Problem14 #LongestCommonPrefix #StringManipulation #Python #AlgorithmDesign #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
#Day257 of Solving #DSA 🚀 LeetCode Question 796 – Rotate String ✅ Just completed LeetCode #796: Rotate String 💪 🧠 Problem Concept: The challenge was to determine if one string can be transformed into another by rotating it. For example, turning "abcde" into "cdeab" — simple in concept, but a neat test of string manipulation and logical thinking. 💡 Key Idea: Instead of performing multiple rotations, I realized that by observing how strings behave when doubled, we can quickly check for possible rotations in a single step. A small trick — but a powerful one. 🔥 Takeaway: Some problems look like they’ll need loops or complex logic, but a sharp observation can make them incredibly clean and efficient. #LeetCode #DSA #Python #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode #1526: Minimum Number of Increments on Subarrays to Form a Target Array Today I tackled an interesting Greedy Algorithm problem that really tests your ability to spot patterns and simplify complex logic. 🧩 Problem Brief: We start with an array of zeros and can increment any subarray by 1 in one operation. The goal is to form the target array using the minimum number of operations. 💡 Key Insight: Instead of simulating every operation, focus on how much each element increases compared to the previous one; each increase represents new operations needed. ⚙️ Formula: operations = target[0] + Σ(max(0, target[i] - target[i-1])) 🧠 Complexity: Time: O(n) Space: O(1) 🎯 Takeaway: Hard problems often become simple once you recognize the pattern behind the process. #LeetCode #Python #DSA #Coding #ProblemSolving #GreedyAlgorithm #LearningEveryday
To view or add a comment, sign in
-
-
💻 Day 1 of Week 2 #Learning_Of_DSA 🚀 Today’s #LeetCode_Problem_2149 – Rearrange Array Elements by Sign. At first glance, it looked straightforward… but the real test was in maintaining order and structure, just like writing clean backend routes 🧠 Approach: ✅ Separate the +ve and -ve value and arrange in resultant array. Complexity: 🕒 Time – O(n) 💾 Space – O(n) Takeaway: Sometimes, the solution isn’t about “big algorithms” — it’s about organized logic. #LeetCode #ProblemSolving #Python #LearnInPublic #SoftwareEngineering #CodingJourney #CareerGrowth #100DaysOfCode #Motivation #MERNStack #DSA
To view or add a comment, sign in
-
-
Day 11 of #100DaysOfLeetCode Problem: 14. Longest Common Prefix Category: Strings / Comparison / Iteration Today’s challenge focused on finding the longest common prefix among an array of strings. It’s a great problem that improves your understanding of string traversal, comparison, and boundary conditions. 🧠 Key Learnings: Iterated character by character through the first string and compared it with all other strings. Carefully handled edge cases where strings had different lengths or no common prefix. Reinforced the concept of early termination when a mismatch is found — improving efficiency. Strengthened skills in iterative string comparison and control flow logic. 🎯 Takeaway: Small details like string length and early exit conditions make a big difference in optimizing even the simplest problems. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Strings #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 37 of #100DaysOfDSA Solved LeetCode Problem #13 – Roman to Integer 🏛️➡️🔢 📌 Problem Insight: The challenge is to convert a Roman numeral string into an integer. Roman numerals use combinations of letters like I, V, X, L, C, D, M — but with a twist: when a smaller value appears before a larger one, it must be subtracted. 💡 Key Learnings: Practiced mapping characters to values using dictionaries. Strengthened understanding of conditional logic in sequential traversal. Reinforced use of iteration and subtraction patterns. Time complexity: O(n) Space complexity: O(1) 📌 Approach (short): Store Roman symbol values in a dictionary. Traverse the string from left to right. If a smaller numeral comes before a larger one → subtract it; else → add it. 👉 Every small problem adds up to strong logic — step by step, symbol by symbol 💪 #LeetCode #DSA #ProblemSolving #100DaysChallenge #Day37 #Python #CodingJourney #RomanToInteger #LogicBuilding
To view or add a comment, sign in
-
-
🚀 LeetCode #1625: Lexicographically Smallest String After Applying Operations Today’s problem was about transforming a numeric string using two operations: adding a value to digits at odd indices and rotating the string, to get the lexicographically smallest result possible. The challenge was to handle infinite possibilities smartly. I used a Breadth First Search (BFS) approach to systematically explore all reachable string states while keeping track of visited ones. 💡 Key Takeaways: - Some problems don’t need a direct formula, they need systematic exploration. - BFS is not just for graphs; it’s a powerful tool for exploring state transitions too. - Modular arithmetic and rotation logic often come together in string manipulation problems. This one was a great reminder that clean logic and state tracking can solve even the most “infinite looking” problems efficiently. #LeetCode #ProblemSolving #Python #DSA #CodingChallenge #Algorithms #BFS #StringManipulation #LearningEveryday
To view or add a comment, sign in
-
-
LeetCode 90-Day Challenge – Day 78 Problem: Find Peak Element Difficulty: Medium Problem: We need to find a peak element in an array, an element that is strictly greater than its neighbors. If multiple peaks exist, returning the index of any one of them is valid. Conceptually, nums[-1] and nums[n] are considered negative infinity, so edge elements can also be peaks. The challenge is to achieve this in O(log n) time. Solution approach: This problem can be efficiently solved using binary search. At each step, we check the middle element and compare it with its right neighbor. If the middle element is smaller than the next one, it means the peak lies on the right half; otherwise, the peak is on the left half. By continuously narrowing down the range, we find a peak element in logarithmic time. #LeetCode #90DaysOfCode #Python #LinkedInChallenge #CodingJourney #ProblemSolving #LeetCodeChallenge
To view or add a comment, sign in
-
-
While handling datetime parameters from an API, I ran into an issue with inconsistent formats especially ISO strings like: "2025-11-04T15:30:00Z" I initially wrote my own utility to parse and standardize the datetime before injecting it into my code. Later, I discovered that Frappe already provides a helper for this: frappe.utils.get_datetime() What’s interesting is that this function isn’t documented in the official Frappe docs but it exists in the source code and supports multiple formats, including those with T and Z. A small discovery, but it saved me time and reminded me to dig into the framework’s codebase before reinventing the wheel. 😉 #Frappe #ERPNext #Python #Datetime
To view or add a comment, sign in
-
-
💻 2011: Final Value of Variable After Performing Operations Today’s challenge was a simple yet interesting warm up problem that tests how efficiently we can track changes in a variable through a series of operations. 🧠 Concept: We start with X = 0, and perform operations like ++X, X++, --X, and X--. Each increment or decrement modifies X by 1, the task is to return the final value after performing all operations. ⚙️ Approach: - A straightforward solution: - Iterate through all operations. - Increment count by 1 for ++ or X++. - Decrement count by 1 for -- or X--. - Return the final count. Even though it’s an easy problem, it’s a great reminder that clarity and precision matter, small details in logic can make a big difference. #LeetCode #Python #CodingPractice #ProblemSolving #100DaysOfCode
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