FastPrepMinimum-Cost Meeting City
Problems/Minimum-Cost Meeting City

Minimum-Cost Meeting City

Google logoGoogle● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the goal of meeting in a city graph. It does not say how to price the shared leg, how to break ties, or what happens when the graph is disconnected. Our version is about 87% the same as the reported question.

An undirected, unweighted graph represents n cities numbered from 0 to n - 1. Travelers start at cities x and y. They may travel separately to a meeting city m, then ride together from m to destination.

The cost of choosing m is dist(x, m) + dist(y, m) + dist(m, destination), so the shared final route is counted once.

Return the meeting city with minimum cost. If several cities have the same minimum cost, return the smallest city index. Return -1 if no city is reachable from both travelers and can reach destination.

Function

minimumCostMeetingCity(n: int, edges: int[][], x: int, y: int, destination: int) → int

Examples

Example 1

n = 7edges = [[0,2],[1,2],[2,3],[3,6],[0,4],[1,4],[4,5],[5,6]]x = 0y = 1destination = 6return = 2

Meeting at city 2 costs 1 + 1 + 2 = 4. Meeting at city 4 also costs 4, so the smaller city index 2 wins the tie.

Example 2

n = 4edges = [[0,1],[2,3]]x = 0y = 2destination = 3return = -1

The travelers start in different connected components, so no valid meeting city exists.

Constraints

  • 1 <= n <= 200000
  • 0 <= edges.length <= 200000
  • Every row of edges is [u, v] with 0 <= u, v < n and u != v.
  • 0 <= x, y, destination < n

More Google Phone Screen questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Maximum Survival Time in a Graph PursuitZip · PHONE SCREENZip interview questions
  • Shortest Distances From an Adjacency MatrixBoston Consulting Group · PHONE SCREENBoston Consulting Group interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Find a Directed Resource Access PathCoreWeave · PHONE SCREEN
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
  • Minimum Friend API CallsMercor · ONSITE INTERVIEWMercor interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minimumCostMeetingCity(int n, int[][] edges, int x, int y, int destination) {
        // write your code here
    }
}
Checking account…