𝗗𝗮𝘆 𝟲𝟲/𝟭𝟬𝟬 — 𝗘𝘃𝗮𝗹𝘂𝗮𝘁𝗲 𝗥𝗲𝘃𝗲𝗿𝘀𝗲 𝗣𝗼𝗹𝗶𝘀𝗵 𝗡𝗼𝘁𝗮𝘁𝗶𝗼𝗻 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

To view or add a comment, sign in

Explore content categories