Q154
What is the time complexity of the following code? public boolean isBalanced(String exp) int len = exp.length(); Stack stk = new Stack (); for(int i = 0; i < len; i++) char ch = exp.charAt(i); if (ch == '(') stk.push(i); else if (ch == ')') if(stk.peek() == null) return false; stk.pop(); return true;
A.
O(logn)
B.
O(n)
AnswerC.
O(1)
D.
O(nlogn)
Answer: Option B
Solution
Answer: Option B
No explanation is given for this question Let's Discuss on Board