I see you haven’t read the full article. Read the whole thing and and my test case as well. The article also mentions a similar tc as mine where your logic would fail and its possible solution. 
Not BST!!
I saw a similar question once just with distinct vertices
Please try to understand the test which I gave and read the definition of Subtree. I think you’re not clear with what a subtree is.
I know what subtree is brooo…but pls check sample on this page:
both your queries are asnwered in sample tc…just have look and then tell me whats the difference if still i am wrong @akshitm16
What do you think the answer to the tc which I gave should be?
Is your test case failing due to TLE???
His logic is incorrect and I have already provided a tc where it fails.
okay got you…answer should be 0…
But pls help modify the above code @akshitm16
NO WA in case which is too long to be displayed on GFG @humane
Your code fails on this test case
As N=10000 You can go for O(N^2) complexity
and try to do it with level order at every vertex which is a possibility for starting node
This will work if you handle cases correctly
The above algorithm can be extended to handle such cases by adding a special character whenever we encounter NULL in inorder and preorder traversals.
Try to think about think (taken from gfg).
with duplicates - O(N^2)
without duplicates - O(N)
Also don’t use this
inmain.find(insub)!=string::npos
This would give TLE.
Did you use KMP? Can you send the code?
code is posted above in post #1
NO KMP. i dont know KMP…just .find function
just added $ functionality @akshitm16