anil is given a sentence as he tries to make a sentence special a sentence can be made special by swapping the character with high frequency with the character having low frequency in the sentence help anil by transforming the sentence into. a special sentence in python.
swap most frequent letter with least given a sentence, swap the occurrences of the most frequenti with the least frequent letter and vice-versa. submisdong note: • consider upper and lower case letters as different . if there are multiple letters with the same frequency, choose the lower case letter that comes earliest in dictionary order o if letters like x and b have same frequency consider x o if letters like x and b have same frequency consider b.
Input: Python is a programming language
Output should be: Python is e progremming lenguega
s = input()
mn, mx = s.count(s[0]), s.count(s[0])
mnc, mxc = 0, 0
for i in range(len(s)):
if s.count(s[i]) > mx and s[i]!=' ':
mx = s.count(s[i])
mxc = i
if s.count(s[i]) < mn and s[i]!=' ':
mn = s.count(s[i])
mnc = i
s1 = []
ss = []
for i in s:
s1.append(i)
ss.append(i)
ss[mnc] = s1[mxc]
ss[mxc] = s1[mnc]
print(''.join(ss))
Comments
Leave a comment