Question 1 here
It is a bit long, but I will summarise what is really asking.
test case 1:
input1, bad phase in password:
bcb (it can be rearranged as bbc, cbb)
input2, password:
abcdcbcb
input3, operation cost:
[a_2, b_3, c_1, d_4, e_0, f_0….. z_0] (rest are op cost zero)
our goal is that we don’t want bcb or b????c???b (subsequence) appearing in password. Same for bbc, cbb. We will remove each letter with cost and return the min total cost operation.
may use stack, but I am not sure.
abcdcbcb -> strip all unrelated chars -> bccbcb
sample stack dry run
run 1:
bad phase:
bcb
bbc
cbb
[b]
[bc]
[bcc]
[bccb_x] (+3)
[bccc]
[bcccb_x] (+3)
total cost = 3+3=6
==
run 2:
bcb
bbc
cbb
[b]
[bc_x] (+1)
[bc_x] (+1)
[bc_x] (+1)
[bb]
[bbb]
total cost = 1+1+1=3
==
run 3:
bcb
bbc
cbb
[b_x] (+3)
[c]
[cc]
[ccb]
[ccbc]
[ccbcb_x] (+3)
total cost = 3+3=6
==
so min cost 1+1+1=3 (not sure correctness, but you get the idea)
==
so at the moment, I need some help to come up a completed algorithm to resolve this problem. I prefer to use javascript, but it is after you.
1