Company: JPMC

Difficulty: easy

Problem Statement

Cost Minimization You are given a string str containing only lowercase Latin letters ( a – z ). Convert every character so that all characters become the same vowel. The allowed vowels are a , e , i , o , and u . Changing a consonant into any vowel costs 10 dollars. If X and Y are vowels, changing X into Y costs |X - Y| dollars, meaning the absolute difference between their lowercase alphabet positions. Find the minimum total cost of transforming the string into a string made of one repeated vowel. If the input string is already equal to one such desired string, print -1 ; otherwise, print the minimum cost. Input Format The input consists of one line containing the string str . Output Format Print one integer: -1 when the input is already a repeated vowel, or the minimum transformation cost otherwise. Constraints 1 <= length(str) <= 250 Every character of str is a lowercase Latin letter. The answer is between 0 and 2500 , inclusive, so a 32-bit signed integer is sufficient. Examp

More JPMC OA questionsInterview experiences