Company: IBM
Difficulty: medium
1. Question 1 A binary string S (containing only 0s and 1s) encodes an encryption key represented by the count of valid substrings in S . A substring is valid if it meets the following conditions: No two adjacent characters are the same. Its length is between minLength and maxLength , inclusive. Return the number of valid substrings, which represents the encryption key for S . Example S = \"1011\", minLength = 2, maxLength = 3 Substring Length Is valid? \"1\" 1 No (Length < minLength) \"0\" 1 No (Length < minLength) \"1\" 1 No (Length < minLength) \"10\" 2 Yes \"01\" 2 Yes \"11\" 2 No (Adjacent repeating) \"101\" 3 Yes \"011\" 3 No (Adjacent repeating) \"1011\" 3 No (Adjacent repeating) Thus, the encryption key for this string is 3 . Function Description Complete the function countValidSubstrings in the editor below. Input Format A string S in binary format. An integer minLength : the minimum length for a valid substring. An integer maxLength : the maximum length for a valid s