Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions