FastPrepValidate a Directed Edge Addition
Problems/Validate a Directed Edge Addition

Validate a Directed Edge Addition

Hive logoHive● MediumFULLTIMEPHONE SCREEN

Updated Jul 2026

QuestionFunctionExamples

Problem statement

You are given a directed graph as a list of source-destination pairs and one proposed directed edge.

Return false if the exact proposed edge already exists or if adding it would create a directed cycle. Otherwise, return true.

Function

isValidEdgeAddition(edges: int[][], newEdge: int[]) → boolean

Examples

Example 1

edges = [[1,2],[2,3],[3,4]]newEdge = [4,1]return = false

Adding 4 -> 1 creates the cycle 1 -> 2 -> 3 -> 4 -> 1.

Example 2

edges = [[1,2],[2,3],[3,4]]newEdge = [1,2]return = false

The exact edge 1 -> 2 already exists.

Example 3

edges = [[1,2],[2,3]]newEdge = [1,3]return = true

The edge is new and does not create a directed cycle.

More Hive Phone Screen questions

  • Diagonal TraversePHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • Find the Unique User with Access to Every CameraVerkada · PHONE SCREENVerkada interview questions
All Hive interview questionsSee Hive hiring insights
Saved
class Solution {
    public boolean isValidEdgeAddition(int[][] edges, int[] newEdge) {
      // write your code here
    }

}
Checking account…