Question: Latest Placement OA Coding Questions Solved | Strings & DP Knapsack
0
Entering edit mode

Question 1: Reverse ASCII Power

Problem Statement: You are given a string Str containing only lowercase letters. Your task is to calculate and print the Reverse ASCII power of the string.

The Reverse ASCII power of the string is calculated as the sum of for . Where is equal to .

(Note: , essentially assigning 'a'=26, 'b'=25... 'z'=1).

Input Format: The first line contains a string Str.

Output Format: Print the Reverse ASCII power of the string.

Example: Input: abc Output: 148

Question 2: Maximum Protein Value (Modified Knapsack)

Problem Statement: Shengij goes to a dairy to buy milkshakes for a party. There are milkshakes numbered from 1 to , where the price of the milkshake is price[i], and the protein value in the milkshake is protein[i].

Shengij has discount coupons, and he can use each coupon at most one time. By using a discount coupon, he can halve the price (floor value) of any milkshake (But no more than one coupon can be applied to the same milkshake). Shengij wants to buy milkshakes such that the sum of prices does not exceed and the total protein value is the maximum possible.

Your task is to help Shengij find the maximum protein value.

Input Format:

  • The first line contains an integer .
  • The second line contains an integer .
  • The third line contains an integer .
  • The fourth line contains space-separated integers denoting the elements of the price array.
  • The fifth line contains space-separated integers denoting the elements of the protein array.

Example: Input: 4 4 1 5 7 2 4 15 10 20 17 Output: 37

Explanation: Shengij can halve the price at most milkshake, and the total price does not exceed . It's better to halve the price of the fourth milkshake and buy the third and fourth milkshake. After buying the third and fourth milkshake, the total price = and the total protein value = . Therefore, the answer is 37.

ADD COMMENTlink 3 days ago admin 1.8k

Login before adding your answer.

Similar Posts
Loading Similar Posts