Abbreviating the Product of a Range
international master · 2145 · lc hard +32 · verified · 24.9% accepted · 91 likes · top 4%
Description
You are given two positive integers left and right with left <= right. Compute the product of all integers in the inclusive range [left, right].
Because the product can be enormous, abbreviate it using these steps:
- Count and strip all trailing zeros from the product, calling the count C.
- For example, 1000 has 3 trailing zeros; 546 has none.
- Let d be the number of digits remaining after removing trailing zeros. If d > 10, express the product as <pre>...<suf> where <pre> is the first 5 digits and <suf> is the last 5 digits. If d <= 10, keep the full number.
- For example, 1234567654321 becomes 12345...54321, while 1234567 stays 1234567.
- Represent the final result as "<pre>...<suf>eC".
- For example, 12345678987600000 becomes "12345...89876e5".
Return the abbreviated product string for the range [left, right].
Example 1:
Example 2:
Example 3:
Code