Hey guys, Today is day 15 of the 100 Days to** LinkedIn Challenge.**
Free For Kindle Readers
If you are Preparing for your Interview. Even if you are settled down in your job, keeping yourself up-to-date with the latest **Interview Problems **is essential for your career growth. Start your **prep **from Here!
Last month, I have been researching to find out the Frequently asked problems from these Companies. I have compiled **100 **of these questions, I am not promising you that you will get these questions in your interview but I am confident that most of these “interview questions” have similar logic and employs the same way of thinking from these set of challenges.
Before we move on to the first problem, If you are wondering why I chose LinkedIn, Yahoo and Oracle over FAANG is because I have completed a challenge Focusing on Amazon and Facebook Interview Questions in this Series:
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +
, -
, *
, /
. Each operand may be an integer or another expression.
Note:
Input: ["2", "1", "+", "3", "*"]
Output: 9
Explanation: ((2 + 1) * 3) = 9
Input: ["4", "13", "5", "/", "+"]
Output: 6
Explanation: (4 + (13 / 5)) = 6
class Solution {
public int evalRPN(String[] tokens) {
Stack<Integer> stack = new Stack<Integer>();
for(String element : tokens)
{
if(!"+-*/".contains(element))
{
stack.push(Integer.valueOf(element));
continue;
}
int second= stack.pop();
int first= stack.pop();
int ans = 0;
switch(element)
{
case "+":
ans = first + second;
break;
case "-":
ans = first - second;
break;
case "/":
ans = first / second;
break;
case "*":
ans = first * second;
break;
}
stack.push(ans);
}
return stack.pop();
}
}
Author: Akshay Ravindran
#software-development #programming #java #interview #coding