Company: IBM Python developer off-campus_8july
Difficulty: medium
You are given a string word consisting of lowercase English letters and an integer k . A substring is called k-interspace if: For every pair of adjacent characters in the substring. The absolute difference between their ASCII values is less than or equal to k. Your task is to: Find the longest contiguous substring of word that satisfies this condition If multiple substrings have the same maximum length, return the one that appears first in the string Examples word = "wedding" k = 0 The first occurring longest 0-interspace substring is "dd". word = "ababbacaabbbb" k = 1 There are two 1-interspace substrings of length 6: "ababba" and "aabbbb". The one that occurs first is "ababba". Function Description Complete the function longestKInterspaceSubstring in the editor with the following parameter(s): string word : the string to analyze int k : maximum difference in character values Returns string : the first occurring longest k-interspace substring of the word Constraints 1 ≤ |word| ≤ 10 ^6