Flipkart Coding Question – Solved

7 Live
Houses in Hackerland The city of Hackerland has many houses, each of which is connected via roads. There are house_nodes number of houses, numbered 0 to house_nodes - 1, where each pair of houses is connected and has a unique shortest path between them. Thus, the network of houses and roads forms an undirected tree structure comprising house_nodes nodes and (house_nodes - 1) edges. Each of the edges has a value denoted by val[i], which can either be 0 or 1. To summarize, the overall tree is represented as follows: house_nodes: the number of nodes house_from, house_to: the arrays representing an undirected edge between house_from[i] and house_to[i] for 1 ≀ i ≀ house_nodes - 1. val[]: the value of each edge in the tree, which can be either 0 or 1. Problem Statement Given the network of houses and roads, the task is to find the number of sequences of length k (h[1], h[2], ... h[k]) such that while visiting: From house h[1] to h[2], Then from h[2] to h[3], And so on until reaching house h[k], Using the unique shortest path between them, at least one edge with value '1' is visited.

Asked in: Flipkart

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |