Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT PLEASE You are given a string S. Deletion of the K-th letter of S costs C[K]. After deleting a letter, the costs of deleting
URGENT PLEASE
You are given a string S. Deletion of the K-th letter of S costs C[K]. After deleting a letter, the costs of deleting other letters do not change. For example, for S= "ab" and C=[1,3], after deleting ' a ', deletion of ' b ' will still cost 3. You want to delete some letters from S to obtain a string without two identical letters next to each other. What is the minimum total cost of deletions to achieve such a string? Write a function: class solution \{ public int solution(string S, int [] c); } that, given string S and array C of integers, both of length N, returns the minimum cost of all necessary deletions. Examples: 1. Given S= "abccbd" and C=[0,1,2,3,4,5], the function should return 2. You can delete the first occurrence of ' c ' to achieve "abcbd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started