Company: Msci_28july
Difficulty: medium
Maximum Coupon Value Problem Description An e-commerce platform offers discount coupons as scratch cards. For a coupon code of lowercase English letters, the value is determined as follows: Each letter is assigned its position value in the alphabet (a=1, b=2, ..., z=26). Character contribution = (character value) (character frequency) modulo (10 9 + 7) Coupon value = sum of all character contributions Example: The coupon "ddzdzz" has a value of (4 3 + 26 3 ) modulo (10 9 + 7) = 17640 Given an initial coupon string and an integer k , create coupon codes using all substrings of length k . Determine the highest possible coupon value among all generated coupon codes. Note: The maximum value can exceed (10 9 + 7). Examples Example 1: Consider coupon = "abcc" and k = 2 . All coupon codes of length 2, and their coupon values are: "ab": value = 1 1 + 2 1 = 3 "bc": value = 2 1 + 3 1 = 5 "cc": value = 3 2 = 9 The maximum coupon value amongst all coupon codes is 9 modulo (10 9 + 7) = 9. Example 2