Company: Chubb_India_26nov
Difficulty: medium
Find Smallest String After One Substring Reversal Problem Description Given a string word and a positive integer k (where 1 ≤ k ≤ |word|), find the alphabetically smallest string possible by reversing at most one substring of size k. Note: A substring is a contiguous sequence of characters within a string. For two strings a and b of the same length, a is alphabetically smaller than b if there exists an index i where a[i] < b[i] and all characters before index i are equal. Examples Example 1: Input: word = "aabdc", k = 2 Output: "aabcd" Explanation: Reverse the substring "dc" to get "aabcd". This is the alphabetically smallest string possible for k = 2. Example 2: Input: word = "aacbd", k = 2 Output: "aabcd" Explanation: Reverse the substring "cb" to get "aabcd". Example 3: Input: word = "aaa", k = 2 Output: "aaa" Explanation: Since all characters are equal, no reversal will make a change. Constraints 1 ≤ k ≤ |word| ≤ 500 ```