This is a verified interview question from De-shaw. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Perfect Route Cycles" covers key patterns like Graphs.
"A large bus company recently expanded its fleet to enhance its in-house transportation system. These buses travel to specific stations, numbered from 1 to n. Currently, the company only operates in two regions. All bus routes are designed as a tree structure, meaning buses departing from any station go to a local hub, then travel to a larger hub or one of the company's destinations. Let's represent stations in the first region with the color white, and stations in the second region with the color black. Given a list of stations and their immediate destinations, your task is to add a route between any two stations such that a perfect route cycle is formed. The characteristics of a perfect route cycle are: - The number of destinations in the cycle is greater than or equal to 3. - All stations in the cycle are in the same region. Count the number of distinct ways to form a perfect route cycle by adding a path between any two stations. This will help the bus company decide where to register its buses for regional travel."
Join thousands of developers practicing for De-shaw.