# Build a Calculator — coding interview question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3632/calculator
Source observed: 2026-11-04T23:11:36.583Z
Last checked: 2026-11-04T23:11:36.583+00:00
Indexed: 2026-11-06T04:21:18.048+00:00

---

# Build a Calculator

**Difficulty:** Medium  
**Category:** Data Structures & Algorithms; Coding  
**Roles:** [Software Engineer](https://www.aced.io/questions?role=swe), [Data Engineer](https://www.aced.io/questions?role=data-engineer), [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer)  
**Companies associated with this question:** [Meta](https://www.aced.io/questions?company=meta-facebook), [Apple](https://www.aced.io/questions?company=apple), [Tesla](https://www.aced.io/questions?company=tesla), [Oracle](https://www.aced.io/questions?company=oracle), [Adobe](https://www.aced.io/questions?company=adobe), [Amazon](https://www.aced.io/questions?company=amazon), [Snap](https://www.aced.io/questions?company=snap)

We provide coding-interview practice through Aced, formerly Exponent. This question asks you to implement a simple arithmetic-expression calculator.

## Problem

Write a function `calc(expr)` that accepts an expression string and returns its answer as a number.

The calculator must:

- Support addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
- Follow the normal order of operations, so multiplication and division are evaluated before addition and subtraction.
- Handle expressions such as `2 + 2` and `4 * 5 - 10 * 2`.

You do not need to support parentheses or improperly formatted strings.

## Examples

```text
calc("1 + 1")       # => 2
calc("5 - 1 - 1")   # => 3
calc("84 / 1 / 2")  # => 42
calc("5/2 - 2*3")   # => -3.5
```

No community answers have been contributed. The question interface includes Question, Solution, and Community tabs, along with Hint 1, Hint 2, Hint 3, Challenge 1, and Challenge 2 controls. Running code requires [sign-up](https://www.aced.io/signup?src=lesson).

## Interview experiences

The page associates this question with three shared interview experiences:

- **Meta · a year ago** — “It was hard. Two medium leet code in 45 minutes and you're alright. System Design needs lots of practice and quick explanations.” — Software Engineer, Mid Level / L4. [Read the experience](https://www.aced.io/experiences/meta-facebook-software-engineer-interview-695d52)
- **Amazon · 2 years ago** — “The overall interview process was well-structured and engaging. The interviewers were professional, communicated expectations clearly, and gave me opportunities to demonstrate my technical and problem-solving skills. I particularly enjoyed the technical discussions and collaborative nature of the interviews. One area that could have been improved was having more clarity around the timeline and expectations between rounds.” — Software Engineer, Intern. [Read the experience](https://www.aced.io/experiences/amazon-software-engineer-intern-interview-6f30ef)
- **Snap · 2 years ago** — “Pretty standard big tech intern interviews. One technical was on the medium/hard side. Interviewer seemed rather uninterested and just wanted to solution rather than any collaboration. The second was a more straight forward and easy problem with an interviewer that was more engaged and collaborative.” — Software Engineer, Intern. [Read the experience](https://www.aced.io/experiences/snap-software-engineer-intern-interview-e676ed)

## Related questions

- [Basic Calculator II](https://www.aced.io/questions/6556/implement-basic-calculator-ii)
- [Build a TTL cache.](https://www.aced.io/questions/6299/design-ttl-cache-system)

## Related courses

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We prepare candidates for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies through mock interviews, frameworks, advice from senior candidates, ML system design, core concepts, coding, and behavioral-interview preparation.

### [Data Engineering Interview Prep](https://www.aced.io/courses/data-engineering)

![Data Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/5XoOCgXlGqN2fa1zaroNWd/9a2e23df48a212bc00d352873feb2d6a/Data_Engineer_Interview_Prep_Hero_Image.jpg?w=800&h=800&fm=webp&q=75)

We prepare candidates for data-engineering roles at Meta, Google, Amazon, Microsoft, Walmart, DoorDash, and other top companies through mock interviews, frameworks, advice from senior candidates, data modeling, pipeline design, SQL, coding, and behavioral-interview preparation.

## Aced interview-preparation areas

We offer courses and practice across Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, Data Engineering, AI Engineering, Investment Banking, Generative AI, Security Engineering, TPM, Solutions Architecture, UX / Product Design, and BizOps & Strategy. We also offer interview experiences, coding questions, practice, mock interviews and coaching, resume review, salary negotiation, job referrals, and other career resources.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3632%2Fcalculator&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3632%2Fcalculator). Opening a form does not execute a tool.