FastPrepFind an A-B-Plus-C Path with Two A Predecessors
Problems/Find an A-B-Plus-C Path with Two A Predecessors

Find an A-B-Plus-C Path with Two A Predecessors

Google logoGoogle● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks whether an A→B+→C path exists. Then it requires at least two A nodes pointing to the first B, and asks for the path to be rebuilt. This version combines both follow-ups and returns the shortest path, with ties going to the alphabetically first. Our version is about 94% the same as the reported question.

A directed graph has a label A, B, or C on every vertex.

Find a path whose first vertex is labeled A, followed by one or more B vertices, and whose final vertex is labeled C. Additionally, the first B vertex on the path must have incoming edges from at least two distinct A-labeled vertices.

Return a valid path with the fewest vertices. If paths tie in length, compare their vertex indices from the start. Choose the path with the smaller index at the first difference. Return an empty array when none exists.

Function

findABPlusCPath(labels: String, edges: int[][]) → int[]

Examples

Example 1

labels = "AABBC"edges = [[0,2],[1,2],[2,3],[3,4]]return = [0,2,3,4]

B vertex 2 has A predecessors 0 and 1; the lexicographically smaller start A is 0.

Example 2

labels = "ABBC"edges = [[0,1],[1,2],[2,3]]return = []

The first B has only one A predecessor.

Example 3

labels = "AABC"edges = [[0,2],[1,2],[2,3]]return = [0,2,3]

One B between A and C satisfies B-plus.

Constraints

  • 1 <= labels.length <= 500.
  • 0 <= edges.length <= 10000.
  • Labels contain only A, B, and C; edges contain valid distinct vertices.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE 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

Similar questions at other companies

  • Bus RoutesUiPath · PHONE SCREEN
  • Minimum Bus Routes to a DestinationPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Find All People with the SecretAmazon · PHONE SCREEN
  • Grid Robot Route with Charging PrioritiesUber · PHONE SCREEN · ONSITE INTERVIEWUber interview questions
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
  • Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Bus RoutesBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Shortest Path Around Moving ParadesZip · PHONE SCREENZip 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[] findABPlusCPath(String labels, int[][] edges) {
        // Write your code here.
    }
}
Checking account…