# CARLOS - April Challenge

Hello everyone! I know that the editorial has been released but ,after several attempts, I don’t understand it.

hey, let me explain you my [solution]. its a simple dynamic programming problem first you have to create a matrix let say MAT[M][M] which stores all possible transformation of characters which is easily calculate using ALL PAIR SHORTEST PATH ALGORITHM (FLOYD WARSHALL ). now you have matrix which tells all possible conversion of one letter to another. suppose if `MAT[x][y]==1` i.e, x is transformable to y, and if `MAT[x][y]=infinite` you cannot transform x to y.
so we write dynamic programming solution,the problem ask for calculating minimum no. of inversion,for this we write O(n*m) solution.start from last element of the array A,suppose first you have a single element (forget about all other element before last element) now single element is always sorted. now start filling the values of sol[] for last element, `sol[i]=min(sol[i+1],MAT[curr][i]);` curr stores the a[last] and `mat[curr][i]` shows weather we can change curr to i where i is between 1 to M.
now for each element which is before last element we can calculate result by `sol[j]=min(sol[j]+MAT[curr][j],sol[j+1];` if `MAT[curr][i]==1` else sol[j]=min(infinite,sol[j+1]); after doing this for all element we get our ans at sol. try out few example you got what this expression says, for better understanding read my code and print values of sol[] using print functions which i explicitly defined for checking sol[] values.