Question: python3.6 5.46 An inversion in a sequence is a pair of entries that are out of order. For example, the characters F and D form
5.46 An inversion in a sequence is a pair of entries that are out of order. For example, the characters F and D form an inversion in string 'ABBFHDL' because F appears before D; so do characters H and D. The total number of inversions in a sequence (i.e., the number of pairs that are out of order) is a measure of how unsorted the sequence is. The total number of inversions in 'ABBFHDL' is 2. Implement function inversions that takes a sequence i.e., a string) of uppercase characters A through Z and returns the number of inversions in the sequence. >inversions ABBFHDL >>>inversions ( ABCD nversions DCBA
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
