Skip to content

Commit aee5727

Browse files
committed
Create README - LeetHub
1 parent de1c4e6 commit aee5727

File tree

1 file changed

+39
-0
lines changed
  • 1475-final-prices-with-a-special-discount-in-a-shop

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/">1475. Final Prices With a Special Discount in a Shop</a></h2><h3>Easy</h3><hr><div><p>You are given an integer array <code>prices</code> where <code>prices[i]</code> is the price of the <code>i<sup>th</sup></code> item in a shop.</p>
2+
3+
<p>There is a special discount for items in the shop. If you buy the <code>i<sup>th</sup></code> item, then you will receive a discount equivalent to <code>prices[j]</code> where <code>j</code> is the minimum index such that <code>j &gt; i</code> and <code>prices[j] &lt;= prices[i]</code>. Otherwise, you will not receive any discount at all.</p>
4+
5+
<p>Return an integer array <code>answer</code> where <code>answer[i]</code> is the final price you will pay for the <code>i<sup>th</sup></code> item of the shop, considering the special discount.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> prices = [8,4,6,2,3]
11+
<strong>Output:</strong> [4,2,4,2,3]
12+
<strong>Explanation:</strong>
13+
For item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4.
14+
For item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2.
15+
For item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4.
16+
For items 3 and 4 you will not receive any discount at all.
17+
</pre>
18+
19+
<p><strong class="example">Example 2:</strong></p>
20+
21+
<pre><strong>Input:</strong> prices = [1,2,3,4,5]
22+
<strong>Output:</strong> [1,2,3,4,5]
23+
<strong>Explanation:</strong> In this case, for all items, you will not receive any discount at all.
24+
</pre>
25+
26+
<p><strong class="example">Example 3:</strong></p>
27+
28+
<pre><strong>Input:</strong> prices = [10,1,1,6]
29+
<strong>Output:</strong> [9,0,1,6]
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= prices.length &lt;= 500</code></li>
37+
<li><code>1 &lt;= prices[i] &lt;= 1000</code></li>
38+
</ul>
39+
</div>

0 commit comments

Comments
 (0)