java.lang.Object
g2101_2200.s2117_abbreviating_the_product_of_a_range.Solution

public class Solution extends Object
2117 - Abbreviating the Product of a Range.<p>Hard</p> <p>You are given two positive integers <code>left</code> and <code>right</code> with <code>left <= right</code>. Calculate the <strong>product</strong> of all integers in the <strong>inclusive</strong> range <code>[left, right]</code>.</p> <p>Since the product may be very large, you will <strong>abbreviate</strong> it following these steps:</p> <ol> <li>Count all <strong>trailing</strong> zeros in the product and <strong>remove</strong> them. Let us denote this count as <code>C</code>. <ul> <li>For example, there are <code>3</code> trailing zeros in <code>1000</code>, and there are <code>0</code> trailing zeros in <code>546</code>.</li> </ul> </li> <li>Denote the remaining number of digits in the product as <code>d</code>. If <code>d > 10</code>, then express the product as <code><pre>...<suf></code> where <code><pre></code> denotes the <strong>first</strong> <code>5</code> digits of the product, and <code><suf></code> denotes the <strong>last</strong> <code>5</code> digits of the product <strong>after</strong> removing all trailing zeros. If <code>d <= 10</code>, we keep it unchanged. <ul> <li>For example, we express <code>1234567654321</code> as <code>12345...54321</code>, but <code>1234567</code> is represented as <code>1234567</code>.</li> </ul> </li> <li>Finally, represent the product as a <strong>string</strong> <code>&quot;<pre>...<suf>eC&quot;</code>. <ul> <li>For example, <code>12345678987600000</code> will be represented as <code>&quot;12345...89876e5&quot;</code>.</li> </ul> </li> </ol> <p>Return <em>a string denoting the <strong>abbreviated product</strong> of all integers in the <strong>inclusive</strong> range</em> <code>[left, right]</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> left = 1, right = 4</p> <p><strong>Output:</strong> &ldquo;24e0&rdquo;</p> <p><strong>Explanation:</strong> The product is 1 × 2 × 3 × 4 = 24.</p> <p>There are no trailing zeros, so 24 remains the same.</p> <p>The abbreviation will end with &ldquo;e0&rdquo;. Since the number of digits is 2, which is less than 10, we do not have to abbreviate it further.</p> <p>Thus, the final representation is &ldquo;24e0&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> left = 2, right = 11</p> <p><strong>Output:</strong> &ldquo;399168e2&rdquo;</p> <p><strong>Explanation:</strong> The product is 39916800.</p> <p>There are 2 trailing zeros, which we remove to get 399168.</p> <p>The abbreviation will end with &ldquo;e2&rdquo;. The number of digits after removing the trailing zeros is 6, so we do not abbreviate it further.</p> <p>Hence, the abbreviated product is &ldquo;399168e2&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> left = 371, right = 375</p> <p><strong>Output:</strong> &ldquo;7219856259e3&rdquo;</p> <p><strong>Explanation:</strong> The product is 7219856259000.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= left <= right <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • abbreviateProduct

      public String abbreviateProduct(int left, int right)