‘1123’ is a ninja string, since ‘1 + 1 = 2’ and ‘1 + 2 = 3’.
Numbers in the ninja string cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. The first line of each test case contains a string ‘S’, representing the string for which you have to determine if this string is a ninja string or not.
For each test case, print a single line as ‘True’ or ‘False’ as per the given condition. The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5 1 <= |S| <= 30 Where ‘T’ represents the number of test cases and ‘S’ represents the given string. Time Limit: 1 second
The idea is here to recursively call the function of string for each length.
This function is used to check whether the the sum of first two previous numbers is equal to the element of the string or not.
This function will take three-parameter: