CS-OA cs-vo Faang

上周周Tik Tok 的OA题目又作妖了Password Reset,全过的同学寥寥无几

An IT Company has asked all its employees to reset theirpasswords according to certain rules. Consider an initial passwords of length n that consists of lowercase English letters. Thefollowing operations can be performed any number of times.
Select any character and change it to any other lowercase Englishletter.
Use the minimum number of operations so that after alloperations, some permutation of the string is a palindromeReturn the resultant string. lf there are multiple palindromicpermutations.return the alphabetically lowest of them.


Note

  1. A permutation of a string contains the same characters, onlythe order of characters can be different. For example, "abcdand "dabc" are permutations of each other.
  2. In order to determine which of the two strings is alphabeticallysmaller, compare their first elements If they are equal - comparethe second, and so on. String x is alphabetically smallelif x<y; where jis the first index in which x and ydiffer.
    Example
    Consider n = 4 and s = aebcd.
    1 Replace 'e' with "b' and s = 'abbcd
  3. Replace 'd' with 'a' s = 'abbca'
    At least 2 operations are required before the string can bepermuted into a palindrome. The palindromic permutations ofthe result are bacab' and 'abcba'. Choose the alphabetically lowerabcba'
    Note that the smallest possible palindrome of 5 characters is'aaaaa', but that requires 4 replacements instead of the minimal 2.
    Function DescriptionComplete the function findResultantString in the editor below.The function must return a string that denotes the resultant stringobtained after minimizing the number of operations
    findResultantString has the following parameter:string s: the original password
    Constraints
    1sns105
    s consists of lowercase English letters only.

下周想再试一下的同学可以联系我

One thought on “上周周Tik Tok 的OA题目又作妖了Password Reset,全过的同学寥寥无几

Leave a Reply

Your email address will not be published. Required fields are marked *