# DUSC Winter Warm-up DWW19C

Can someone explain what was the approach to solve this problem Anjali and the tasty treat

It is a cakewalk problem. You can just store the character count for all the alphabets in the strings A and B. And then just check for each character if itâ€™s occurrence is less in A than B, if so, just add the difference to the answer.

2 Likes

Check for the intersections between the two strings while including duplicate elements.

@ankushkhanna , there was swap ingredients â€¦ first i thought swapping ingredients between A and B and then got to know swapping ingredients in A to get the same order as B

Actually it is well mentioned in the line just before the operations:

There are three types operations which she can perform any number of times (including 0) and in any order on dish A to make dish B

Donâ€™t miss the "on dish A" part.

oh ok
Didnt read the question properly as i was in hurry in the contest
Sorry

Oh! Itâ€™s just fine. No need to be sorry. Weâ€™re all here to learn.

1 Like

But then, there can be a case where we deleted a character (cost 0) and later tried to add the same character at the end of B(cost 1). so, in this case, the frequency of that character is the same in both A and B, but cost is 1.

But it is not optimal to do such an operation. It will only add up cost. The best part is (which is making this problem very very easy) that swapping a pair and deletion operations are free, so we just need to focus on the addition part, and add in a way so as to minimize the total cost (expenditure).

So we should never delete a character which is required, we just need to add the deficit characters, thatâ€™s it.

Hope you got it.

1 Like

achaâ€¦ got it! the same operation can be achieved by a series of swaps and hence thatâ€™ll be chosen which doesnâ€™t alter the costâ€¦

yeahâ€¦ got itâ€¦ thank you!