Company: infoedge_18oct
Difficulty: medium
Count Of Shops Problem Description There is a Market that has N shops. You are given a 0-indexed array of paths where paths[i] indicate that there is a directed edge from shop i to shop paths[i] . Assume the following process in the graph: You start from any shop 's' and keep visiting other shops through paths until you reach a shop that you have already visited before on this same process. Return an array count where Count[i] indicates the number of different shops that you will visit if you start the process from shop i . Note: There are only N directed edges (meaning each shop has exactly one outgoing edge). Input Format The first line of input contains an integer N. The next N lines of the input contain N integers, representing the paths array where the i-th integer is paths[i] . Output Format It will be an array of counts that indicates the number of different shops that you will visit. Examples Example 1: Input: 4 1 2 0 0 Output: 3 3 3 4 Explanation: N=4 The paths define the foll