I was recently solving (https://codeforces.com/contest/1900/problem/C) . I did DFS approach first https://codeforces.com/contest/1900/submission/239489864. But it gave TLE on testcase 5 but when did using BFS 239489864. It got accepted but why? Both are just brute force yet one works not other. Please help
Auto comment: topic has been updated by GonnaTry (previous revision, new revision, compare).
try passing the string by reference. your code would create a copy of the string upon each dfs call.
Thanks it worked.