Can anyone tell me what’s the need of topological sort in this question ?? Cant we do this just running DFS on any random node and continuing until all the nodes are visited and in DFS we keep an array of size 26 in each node and store the count of that current character and update the child node array accordingly and when we are done with a path (root to leaf) we take maximum count of that array in current node(leaf node) ! And finally printing the count ! If there is a cycle print -1 instead ! My code fails for the 3rd sample case !
Ques : Problem - 919D - Codeforces
My code : Submission #38124119 - Codeforces
Pls help !1