`{"id":"cf8ff853-1673-44b2-b2e9-0f5fcf18adb6","name":"Basic Calculator Iii","description":"1. Implement a basic calculator to evaluate a simple expression string.\r\n2. String will contain only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. \r\n3. All intermediate results will be in the range of [-2^31, 2^31 - 1].","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 10^4\r\n2. s consists of digits, '+', '-', '*', '/', '(', and ')'.\r\n3. s is a valid expression.","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<stack>\n#include<string>\nusing namespace std;\n\nint calculate(string s) {\n // Write your code here\n}\n \nint main(){\n string s ;\n getline(cin, s);\n int res = calculate(s);\n cou"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calculate(String s) {\r\n return 0;\r\n }\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int result = calculate(read.readLine());\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"2*(5+5*2)/3+(6/2+8)","sampleOutput":"21\r\n","questionVideo":"https://www.youtube.com/embed/s_EKZnQUOp0","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"20a0c894-dd60-4b48-9510-43b587e949ad","name":"Basic Calculator Iii","slug":"basic-calculator-iii","type":1}],"next":{"id":"abf737cd-0baf-48b2-a3b5-d61728051d91","name":"Basic Calculator Iii Hard MCQ","type":0,"slug":"basic-calculator-iii-hard-mcq"},"prev":{"id":"5c9871cd-2341-40cf-80ec-0d8452a78c3d","name":"Basic Calculator II","type":3,"slug":"basic-calculator-ii"}}}`

# Basic Calculator Iii

1. Implement a basic calculator to evaluate a simple expression string. 2. String will contain only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. 3. All intermediate results will be in the range of [-2^31, 2^31 - 1].

`{"id":"cf8ff853-1673-44b2-b2e9-0f5fcf18adb6","name":"Basic Calculator Iii","description":"1. Implement a basic calculator to evaluate a simple expression string.\r\n2. String will contain only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. \r\n3. All intermediate results will be in the range of [-2^31, 2^31 - 1].","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 10^4\r\n2. s consists of digits, '+', '-', '*', '/', '(', and ')'.\r\n3. s is a valid expression.","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<stack>\n#include<string>\nusing namespace std;\n\nint calculate(string s) {\n // Write your code here\n}\n \nint main(){\n string s ;\n getline(cin, s);\n int res = calculate(s);\n cou"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calculate(String s) {\r\n return 0;\r\n }\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int result = calculate(read.readLine());\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"2*(5+5*2)/3+(6/2+8)","sampleOutput":"21\r\n","questionVideo":"https://www.youtube.com/embed/s_EKZnQUOp0","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"20a0c894-dd60-4b48-9510-43b587e949ad","name":"Basic Calculator Iii","slug":"basic-calculator-iii","type":1}],"next":{"id":"abf737cd-0baf-48b2-a3b5-d61728051d91","name":"Basic Calculator Iii Hard MCQ","type":0,"slug":"basic-calculator-iii-hard-mcq"},"prev":{"id":"5c9871cd-2341-40cf-80ec-0d8452a78c3d","name":"Basic Calculator II","type":3,"slug":"basic-calculator-ii"}}}`

Editor

# Basic Calculator Iii

hard

1. Implement a basic calculator to evaluate a simple expression string. 2. String will contain only non-negative integers, '+', '-', '*', '/' operators, and open '(' and closing parentheses ')'. 3. All intermediate results will be in the range of [-2^31, 2^31 - 1].

## Constraints

1. 1 <= s.length <= 10^4 2. s consists of digits, '+', '-', '*', '/', '(', and ')'. 3. s is a valid expression.

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}2*(5+5*2)/3+(6/2+8)`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}21 ```

Question Video

Discussions

Show Discussion

Related Resources