FastPrepDetect a Cycle in Directed Hate Relationships
Problems/Detect a Cycle in Directed Hate Relationships

Detect a Cycle in Directed Hate Relationships

Arcesium logoArcesium● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: Reported in an Arcesium intern online assessment. The report's wording about dividing people into teams does not fit the method the report says was accepted. Our rebuilt version follows the directed-cycle reading. It is about 75% the same as the reported question.

There are n politicians labeled from 0 to n - 1. You are given a list of directed hate relationships hatePairs, where each pair [u, v] means that politician u hates politician v.

Return true if the directed graph formed by these relationships contains a directed cycle. Otherwise, return false.

A directed cycle exists when it is possible to start at a politician, follow one or more hate relationships in their stated direction, and return to the starting politician.

Function

hasDirectedHateCycle(n: int, hatePairs: int[][]) → boolean

Examples

Example 1

n = 4hatePairs = [[0,1],[1,2],[2,0],[2,3]]return = true

The relationships 0 -> 1, 1 -> 2, and 2 -> 0 form a directed cycle, so the result is true.

Example 2

n = 4hatePairs = [[0,1],[0,2],[1,3],[2,3]]return = false

Every relationship moves toward politician 3, and no path returns to an earlier politician. The graph has no directed cycle, so the result is false.

More Arcesium Online Assessment questions

  • City Infection NumberOA · Seen Jul 2025
  • Minimum Tunnel Crossing TimeOA · Seen Jul 2025
  • Product of Subset MaximaOA · Seen Jul 2025
  • Reconstruct the Root StreamOA · Seen Jul 2025
  • Add DigitsOA · Seen Aug 2023
  • Binary Tree Maximum Path SumOA · Seen Aug 2023
  • Reverse First K Characters in Every 2K BlockOA · Seen Aug 2023
  • Robo Data Sharing DirectionOA · Seen Jul 2023
  • Capital Gains Tax from TradesOA · Seen Feb 2021
  • K-th Character in an Infinite StringOA · Seen Aug 2020

Similar questions at other companies

  • Can You Finish All Courses?Intuit · OAIntuit interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Delivery ServiceInMobi · OAInMobi interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course SchedulePlaud · ONSITE INTERVIEW
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Audit Discounted Category AncestorsFaire · ONSITE INTERVIEW
  • Course ScheduleNykaa · PHONE SCREENNykaa interview questions
All Arcesium interview questionsSee Arcesium hiring insights
Saved
class Solution {
    public boolean hasDirectedHateCycle(int n, int[][] hatePairs) {
        // Write your code here.
    }
}
Checking account…