Count Distinct Passwords
Weak passwords are likely to be hacked and misused. Due to this, developers at Amazon regularly come up with new algorithms to check the health of user passwords. A new algorithm estimates the variability of a password as the number of distinct password strings that can be obtained by reversing any one substring of the original password. Given the original password that consists of lowercase English characters, find its variability.
Note: A substring is a contiguous sequence of characters within a string. For example 'bcd', 'a', 'abcd' are substrings of the string 'abcd' whereas the strings 'bd', 'acd' are not.
Complete the function countDistinctPasswords in the editor below.
countDistinctPasswords has the following parameter:
string password: the original password
Returns
long integer: the number of distinct password strings that can be formed
1Example 1

2Example 2
Constraints
Limits and guarantees your solution can rely on.