Hello,
I just finished the Cisco Placement Test for batch 2026(India). It was 40 MCQ + 2 CP problems. Both of the CP problems were tree based, but I wasn't able to solve either of them. Definitely not going to get selected. But would like to discuss the problems and possible solutions.
First Problem: Given a tree with n vertices (Some of the vertices contains coin) and a binary string of length n denoting which vertex contains coins. You can collect a coin if the number of edges from your current vertex to the coin vertex is <= 2. You can start with any vertex, but after collecting all the coins you need to end at vertex you started at. what's the minimum path length you need to collect all the coins n <= 1e5 (length of the path is number of edges in the path).
Second Problem: Given a tree with n vertices. a start_vertex and an end_vertex, with a list of vertex, starting from the start_vertex you need to visit all the vertex in the list of vertex (in any order) and finish at the end_vertex. Find the minimum path that does this.
For the first problem I was really clueless how to solve it maybe there's some DP approach, For the second problem it's possible to solve it with multiple dfs but It felt to complicated to code in the given time.
Is there any elegant or easier way to solve these problems. Any discussion will be helpful.
Full text and comments »