HackerRank Çözümleri – Minimum Loss

HackerRank içerisinde bulunan “Minimum Loss” sorusunun açıklaması ve çözümü. Bu soruda size ev fiyatları olarak verilen bir integer dizisi içerisinde, önce satın almak koşulu ile, satın alınıp sonrasında satış yapıldığında elde edebileceğiniz minimum zarar soruluyor.

► HackerRank – Minimum Loss: https://www.hackerrank.com/challenges/minimum-loss/problem

► Problem açıklaması:

Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss.

Example:

price = [20, 15, 8, 2, 12]

Her minimum loss is incurred by purchasing in year 2 at price[1] = 15 and reselling in year 5 at price[4] = 12. Return 15 – 12 = 3.

Function Description

Complete the minimumLoss function in the editor below.

minimumLoss has the following parameter(s):

int price[n]: home prices at each year

Returns int: the minimum loss possible

Sample Input 0

3

5 10 3

Sample Output 0

2

Sample Input

1

5 20 7 8 2 5

Sample Output 1

2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.