FastPrepFind Minimum City Hops
Problems/Find Minimum City Hops

Find Minimum City Hops

Amazon logoAmazon● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Special thanks to a friend who shared that this problem appeared in an Amazon Online Assessment. We used September 3, 2026, the day this was shared, as the first last-seen date. We'll take it from here. The shared excerpt gives the city format, the rule for which cities are next to each other, the goal of the fewest hops, and the result when a city cannot be reached. We added the function signature, the promise that the start and end are valid, and the examples. Our version is about 97% the same as the reported question.

You are given an array of cities named cities. Each city is represented by a three-character lowercase string.

Two cities are directly connected when their strings differ in exactly one character position.

Starting from startCity, you may hop only between directly connected cities in cities. Return the minimum number of hops needed to reach endCity. If endCity is not reachable, return -1.

Function

findMinimumCityHops(cities: String[], startCity: String, endCity: String) → int

Examples

Example 1

cities = ["abc","abd","acd","xyz"]startCity = "abc"endCity = "acd"return = 2

One shortest route is abc to abd to acd. Each hop changes exactly one character, so the route uses 2 hops.

Example 2

cities = ["aaa","aab","abb","bbb"]startCity = "aaa"endCity = "bbb"return = 3

The route aaa to aab to abb to bbb changes one position per hop and reaches the destination in 3 hops.

Example 3

cities = ["abc","abd","xyz"]startCity = "abc"endCity = "xyz"return = -1

The city xyz is not connected to the component containing abc, so it cannot be reached.

Constraints

  • cities contains at least one city.
  • Every value in cities, as well as startCity and endCity, consists of exactly three lowercase English letters.
  • startCity and endCity each appear in cities.

Source note: Amazon OA sighting shared by a FastPrep contributor.

More Amazon Online Assessment questions

  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Merge ConflictsOA · Seen Nov 2026
  • Shopping Cart BillingOA · Seen Nov 2026

Similar questions at other companies

  • Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
  • Shortest Route Through a Traced MazeDuolingo · OADuolingo interview questions
  • Minimum Genetic MutationBenchling · OABenchling interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
  • Find a Directed Resource Access PathCoreWeave · PHONE SCREEN
  • Word LadderGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int findMinimumCityHops(String[] cities, String startCity, String endCity) {
        // Write your solution here.
    }
}
Checking account…