Databricks | Technical Phone Screen | San Francisco

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-01-26Added By Anonymous
Source: Link

You are given n randomly generated connected graphs. You need to merge these n graphs into a single graph by randomly picking one graph and connecting with the another. Each graph has to be equally likely to be picked up.


Example: if there are three graphs x, y, z - then each time your function is called, it should return one of the following connected single graph equally likely:

x -- y -- z

or

x -- z -- y

or

y -- x -- z


Each graph x, y, z can have any number of nodes and x, y, z are themselves connected. You need to decide how to represent the graph.

Every time the function is called, it has to randomly return one of the possible connected graphs.

Comments