DPWORLD Coding Question – Solved

3 Live
You are given an integer 'n', indicating that there are n family members labeled from 1 to n. This large family completes dinner in several rounds due to limited seating at the dining table (k seats) and prerequisite relationships between members, which may be children eating first, senior members eating first, or any other reason. You are also given an array of relations where relations[i] = [member1, member2], representing prerequisite relationships where member1 must have dinner before member2. Return the minimum number of rounds needed to have dinner for all members. Note: The value of k is equal to the smallest prime factor of n. Input Format: - The first line of input contains an integer n. - The second line contains an integer x (number of relations). - The third line contains an integer 2 (indicates two integers are required in each relation). - The next x lines each contain two integers representing a relation. Constraints: - 2 <= n <= 15 - 0 <= relations.length <= n * (n - 1) / 2 - relations[i].length == 2 - 1 <= member1, member2 <= n - member1 != member2 - All the pairs [member1, member2] are unique. - The given graph is a directed acyclic graph (DAG). Output Format: - Return an integer count that indicates the minimum number of rounds needed for all family members to take dinner. Sample Testcase Input: 4 3 2 2 1 3 1 1 4 Output: 2

Asked in: DPWORLD

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


from collections import defaultdict, deque
import heapq
def minNumberOfRounds(n,relations):
    indegree = defaultdict(int)
// ... rest of solution available after purchase

πŸ”’ Please login to view the solution

Explanation


No explanation available for this question.


Related Questions