Relative Content

Tag Archive for c++stackdsa

Not able to solve the sum of range minimum with normal concept

i was trying to solve the leetcode problem sum of range minimum i did pretty normal stuff like get the previous smallest numbers index and the next smallest numbers index for each no. stored so that i could find the range length as i – pse[i] and nse[i] – i but.. its not working for [71,55,82,55]

Postfix to Infix Conversion – I am getting TLE. How can I optimize my code?

`class Solution { public: string postToInfix(string exp) { // Write your code here stack<string>st; for(int i=0;i<exp.length();i++){ if(!isalpha(exp[i])){ string A=st.top(); st.pop(); string B=st.top(); st.pop(); string s=”(” + B + exp[i] + A + “)”; st.push(s); } else st.push(string(1,exp[i])); } return st.top(); } };` The problem is from geeks of geeks.I am getting time limit exceeded.What can […]