Question
Write a JAVA solution for You are given a string in which a cost of deletion is assigned to every letter.Find the minimum total cost
Write a JAVA solution for You are given a string in which a cost of deletion is assigned to every letter.Find the minimum total cost of deletions to achieve a string without 2 identical letters next to each other. Task Description: 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 2 identical letters next to each other.What is the minimum total cost of deletions to achieve such a string? write a function: def solution(S,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 occurance of 'c' to achieve "abcbd". 2.Given S = "aabbcc" and C = [1,2,1,2,1,2], the function should return 3.By deleting all the letters with a cost of 1,you can achieve string "abc". 3.Given S = "aaaa" and C = [3,4,5,6], the function should return 12.You need to delete all but one letter 'a',and the lowest cost of deletions is 3+4+5=12. 4.Given S = "ababa" and C = [10,5,10,5,10], the function should return 0.there is no need to delete any letter. Write efficient algorithm for following assumptions . string S and array C have length equal to N. . N is an integer within the range [1..100,000]; . string S is made only of lowercase letters (a-z); . Each element of array C is an integer within the range[0..1,000].
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