Company: Microsoft SDE2_23june

Difficulty: medium

Problem Statement

Determine the length of the shortest substring to delete from a string s of length n , so that the resulting string contains only distinct characters. A substring is a sequence of characters that appear consecutively within a string. If a substring is deleted, the remaining parts of the string are joined together. If no deletion is necessary, the answer should be 0. Example s = "abbcbcbk" There are three optimal choices: "abobcbk" , "abcbbbk" , and "bcbcbk" . The bold characters are the substrings to remove. All result in "abck" which has only distinct characters. The removed substring must have at least 3 characters. Return 3. Function Description Complete the function findShortestSubstring in the editor with the following parameter: s : the string to analyze Returns: int : an integer representing the length of the shortest substring that should be deleted Constraints 1 ≤ n ≤ 10 5 s consists of lowercase English letters only. Input Format For Custom Testing The first and only li

More Microsoft SDE2_23june OA questionsInterview experiences