Faulty Keyboard Codevita 9 Solution 2020

Faulty Keyboard Codevita 9 Solution

Mr. Wick has a faulty keyboard. Some of the keys of the keyboard don’t work. So he has copied all those characters corresponding to the faulty keys on a clipboard. Whenever those characters need to be typed he pastes it from the clipboard. In typing whatever is required he needs to make use of paste, backspace and cursor traversal operations. Help him in minimize the number of operations he needs to do to complete his typing assignment. Each operation has one unit weightage.

Constraints

  • 1 <= S <= 16
  • 1 <= T<= 10^4

String T and S will only be comprised of letters a-z and digits 0-9

Input

  • First line contains text T to be typed Second line contains string S of all the faulty keys pasted on clipboard

Output

  • Print the minimum number of operations required for typing the text T

Time Limit
1

Examples:
Example 1

Input

experience was ultimate

ew

Output

14

Explanation

experience =(2+2+2+2) =[ {p+b} + {p+b} +{p+b} +{p+b} ]

was=(4)=[ p+m+b+m]

ultimate=(2)=[ p+b ]

where p=paste, b=backspace ,m= move cursor

Example 2

Input

supreme court is the highest judicial court

su

Output

17

Explanation

supreme =(1) =[ p]

court=(4)=[ p+m+b+m]

is=(2)=[ p+b ]

the=(0)

highest=(2)=[p+b]

judicial=(4)=[p+m+b+m]

court=(4)=[p+m+b+m]

SOLUTION

Program: Faulty Keyboard Codevita 9 Solution in python

p=input("")
q=input("")
s=""
p1=list(p.split(" "))

q1=list(q.split(" "))

for t in range(0,len(q1)-1):
    c=[0 for i in range(t,len(q1))]

for i in p1:
    for j in range(len(q1)):
        k1=0
        while(k1):
            m2=c.index(m1)
            for i in range(m2,len(c)):
                if(c[i]==m1):
                    if(ord(q1[i])<ord(q1[m2])):
                        m2=i
                    else:
                        m2=c.index(m1)
                        q1[m2],q1[t]=q1[t],q1[m2]
    s+=q1[0]
print(len(s))

Codevita Season 9 All Questions Solution

Leave a Comment

19 + ten =