Company: LinkedIn_SDE intern_On-campus_6july

Difficulty: medium

Problem Statement

Hackerland is a country consisting of n cities, structured as a tree graph. Each city is uniquely numbered from 1 to n, and the country is connected by n - 1 roads, such that the graph is fully connected and acyclic. The i th road directly connects two cities: edge_from[i] and edge_to[i]. The mathematicians of Hackerland want to assign a unique prime number as an index to each city. The assignment must satisfy the following conditions: Each city must be assigned a prime number between 2 and 100 (inclusive). For any two cities directly connected by a road, the sum of their assigned indices must not be a prime number. Your task is to determine the total number of valid ways to allocate indices to all cities such that the above conditions are met. Since the number of valid allocations may be very large, return the result modulo (10 9 +7) Example Suppose n = 2, edge_from = [1], edge_to = [2] 1 | 2 There are 25 primes between the numbers in the range [2, 100]. Hence there are a total of 625

More LinkedIn_SDE intern_On-campus_6july OA questionsInterview experiences