# Lexicographic Grid Travel — 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/5567/lexicographic-grid-travel
Source observed: 2026-11-04T23:18:11.035Z
Last checked: 2026-11-04T23:18:11.035+00:00
Indexed: 2026-11-06T10:56:42.494+00:00

---

# Lexicographic Grid Travel.

We provide this coding interview question through Aced, formerly Exponent. It is categorized under [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) and [Coding](https://www.aced.io/questions?type=coding), and is associated with the [Software Engineer](https://www.aced.io/questions?role=swe) role and [Databricks](https://www.aced.io/questions?company=databricks). The question is marked as having been last asked a year ago and is part of the interview practice experience on Aced.

## Problem

You are given an `m × n` grid with a start cell `S` and a destination cell `D`. Each cell contains a value from `{0, 1, 2, 3, 4}`:

- `0` means the cell is blocked.
- `1` corresponds to a bicycle.
- `2` corresponds to a motorbike.
- `3` corresponds to a car.
- `4` corresponds to a bus.

You are also given matrices `T` and `C`, representing the time and cost to enter each cell.

Choose exactly one mode of transport for the entire trip; switching modes is not allowed. For the selected mode, move between adjacent compatible cells using only up, down, left, or right moves.

The objective is to find a path from `S` to `D` that minimizes `(total_time, total_cost)` lexicographically:

1. Prefer the path with the smaller total time.
2. If multiple paths have the same total time, prefer the one with the smaller total cost.

Return the minimal `(time, cost)` across all transport modes. Return `-1` if the destination is unreachable.

## Access and completion

The question offers an answer area. Submitting an answer marks the question complete. Answering requires logging in or signing up. Detailed company statistics for the question are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

## Community answers

No community answers have been contributed.

## Related courses

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

We help candidates prepare for software engineering interviews at Google, Amazon, Microsoft, Meta, Apple, and other companies. The course includes mock interviews, frameworks, and advice from senior candidates, with practice covering data structures, algorithms, system design, people management, and behavioral interviews.

### [System Design Interviews](https://www.aced.io/courses/system-design-interviews)

We teach approaches for answering system design questions across product, infrastructure, and AI domains. The course includes in-depth video examples, written breakdowns, reference patterns, and mock interview videos featuring senior engineers and managers.

## Aced interview-preparation areas

We offer interview preparation through courses and question collections covering 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, technical program management, solutions architecture, UX/product design, and BizOps & Strategy.

Our question collections include product management, behavioral, coding, system design, SQL, machine learning, investment banking, and data engineering questions. We also offer practice, mock interviews and coaching, resume review, salary negotiation, job referrals, and related resources.

## Source links

- [All Questions](https://www.aced.io/questions)
- [Aced home — formerly Exponent](https://www.aced.io/?src=nav)
- [Log in](https://www.aced.io/login?src=nav)
- [Sign up](https://www.aced.io/signup?src=nav)

---

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