Some test cases are giving wrong answer,while 1 is giving tle

Hello @sattyrajpoot39,

  1. You are checking for 1 and 0 in your check function.
    Your code will return 1 for these two digits.

  2. The stoi() function would not work for large numbers. It will give a runtime error.
    Rather use the loop to convert a string into an integer.

  3. Also, If you would print num, then you would realise that your code is initially checking for all the subarrays/substrings that are starting from index i=0. Correct?
    You are required to start from all subarrays of the smallest size i.e. 1 and you can increase the size gradually.
    Mark the index of the digit as 1 if it has been used in a previously detected CB number.

You can refer to the following code, for better understanding:

Hope, this would help.
Give a like, if you are satisfied.