# Check if a numeric string can be split into substrings having difference between consecutive numbers equal to K

Check if a numeric string can be split into substrings having difference between consecutive numbers equal to KGiven a numeric string S consisting of N digits and a positive integer K, the task is to check if the given string can be split into more than one substrings with difference between consecutive substrings equalt to K.Examples:Input: S = “8642”, K = 2Output: YesExplanation: Split the given string as {“8”, “6”, “4”, “2”}. Now, the difference between the consecutive substrings is K(= 2).Input: S = “1009896”, K = 0Output: NoApproach: The given problem can be solved by generating all possible substring of the given string and check if the concatenation of any subset of the generated substring is equal to the given string S and the consecutive difference of the number as a substring is K, then print Yes. Otherwise, print No. Follow the below steps to solve the problem:Iterate over the range [1, N/2] using the variable i and perform the following steps:After completing the above steps, if the value of ans is false, print “No”. Otherwise, print “Yes”.Below is the implementation of the above approach:C++  #include using namespace std;  void isPossible(string s, int K){    bool valid = false;    long firstx = -1;          int n = s.length();              for (int i = 1; i 