Microsoft | SDE | 25 November

Microsoft · Question · Posted Apr 2020

A palindrome is a string of letters that is equal to itself when reversed. Given an input string, not necessarily a palindrome, compute the number of times you need to swap to transform the string into a palindrome. By swap we mean reversing the order of two adjacent symbols. For example, the string "mamad" may be transformed into the palindrome "madam" with 3 swaps: swap "ad" to get "mamda" swap "md" to get "madma" swap "ma" to get "madam" The ...

The full answer & interview discussion are available to premium members.

Log in Create a free account