[Leetcode]1. Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
Continue reading “[Leetcode]1. Two Sum”

[Leetcode problems]1475. Final Prices With a Special Discount in a Shop

Given the array prices where prices[i] is the price of the ith item in a shop. There is a special discount for items in the shop, if you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i], otherwise, you will not receive any discount at all.

Return an array where the ith element is the final price you will pay for the ith item of the shop considering the special discount.

Examples:
Input: prices = [8,4,6,2,3] Output: [4,2,4,2,3]
Input: prices = [1,2,3,4,5] Output: [1,2,3,4,5]
Continue reading “[Leetcode problems]1475. Final Prices With a Special Discount in a Shop”