A Special Keyboard

PHOTO EMBED

Wed Oct 05 2022 09:48:07 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
  public:
    int findTime(string S1, string S2) {
        // code here
        int n=S1.size();
        int m=S2.size();
        unordered_map<char,int>mp;
        for(int i=0;i<n;i++)
        {
            mp[S1[i]]=i;
        }
        int ans=0;
        int temp=0;
        for(int j=0;j<m;j++)
        {
            int b=mp[S2[j]];
            ans+=abs(b-temp);
            temp=b;
        }
        return ans;
    }
};
content_copyCOPY

Medium and good

https://practice.geeksforgeeks.org/problems/228d0aa9f26db93ee5b2cb3583dbd4b197447e16/1