# Maximum Profit — 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/3630/maximum-profit
Source observed: 2026-11-04T23:28:12.133Z
Last checked: 2026-11-04T23:28:12.133+00:00
Indexed: 2026-11-06T13:33:23.532+00:00

---

# Maximum Profit

**Difficulty:** Easy  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) · [Coding](https://www.aced.io/questions?type=coding)

We provide this coding interview question for practicing an efficient arbitrage calculation. You and a friend are starting an international trading business. Given current widget prices in cities around the world, choose where to buy and where to sell to maximize profit: buy in the lowest-priced city and sell in the highest-priced city.

## Task

Write a function `max_profit(prices)` that efficiently finds the two cities producing the largest price difference.

- **Input:** A dictionary with cities as keys and prices as values.
- **Output:** An array containing the city names in `(min, max)` order: the buying city first and the selling city second.
- If `prices` is empty, return `None`/`null`, depending on the programming language.
- If no profit can be earned, including when the maximum profit is `0`, return `None`/`null`.
- In C++, return `{"", ""}` in those cases.

## Example

```python
prices = {'London': 72, 'New York': 70, 'Tokyo': 67, 'Miami': 62}
max_profit(prices) # => ['Miami', 'London']
```

The question interface includes solution, community, hint, challenge, code-editor, output, test-results, and console areas. Running code requires [signing up](https://www.aced.io/signup?src=lesson). Detailed company statistics are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

## Interview experiences

Four shared interview experiences are associated with this question:

1. [Capital One — Business Analyst interview](https://www.aced.io/experiences/capital-one-business-analyst-interview-5b94e9), **Entry Level / L3**, reported **5 months ago**. The interview lasted about four hours and included behavioral questions about past experience, handling situations, teamwork, leadership, and problem-solving; quantitative and analytical math questions; and a technical/conceptual section assessing fundamental technical concepts, reasoning, and technical problem-solving rather than simple fact recall.
2. [Meta — Data Scientist interview](https://www.aced.io/experiences/meta-facebook-data-scientist-interview-7255ae), **Mid Level / L4**, reported **5 months ago**. The contributor described it as casual and easy, with standard, not difficult questions and many follow-ups.
3. [Google — Software Engineer interview](https://www.aced.io/experiences/google-software-engineer-interview-0af9e4), **Entry Level / L3**, reported **7 months ago**. The contributor described it as pretty easy but very long; the technical portion required LeetCode practice and no system design, and interviewers helped when the candidate was stuck.
4. [Google — Software Engineer interview](https://www.aced.io/experiences/google-software-engineer-interview-965bee), **Entry Level / L3**, reported **a year ago**. The process focused on data structures, algorithms, and problem-solving. The contributor found interviewers professional, explained their approach, and noted that time management during solution optimization could have been better.

## Related courses

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

![Data Analyst Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/72OTqij57b2TklhaD2vrdV/be0dae6242904970d1696e5a4d858e18/AdobeStock_1357126576.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for data analyst interviews for product, marketing, and business analyst roles. The course covers real take-home case studies, technical and dashboarding skills, and strategies from interviewers at technology companies and startups.

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

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for data science roles at Google, Amazon, Microsoft, Meta, Apple, and other companies through mock interviews, frameworks, and advice from senior candidates. Practice areas include statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.

## Aced interview-preparation resources

We offer interview courses for 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, practice questions, coaching, resume review, salary negotiation, job referrals, resources, and business and university programs.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3630%2Fmaximum-profit&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%2F3630%2Fmaximum-profit). Opening a form does not execute a tool.