REST API: Discounted Price
Learn this problemProblem statement
Given a barcode, query the API at https://jsonmock.hackerrank.com/api/inventory?barcode=barcode and return the item's discounted price.
The response is a JSON object with 5 fields. The essential field is data:
data: Either an empty array or an array with a single object that contains the item's record.In the data array, the item has the following schema:
barcode: the barcode for the product (String)price: the gross selling price (Number)discount: the discount percent to apply (Number).
page, per_page, total, total_pages, etc. are not required for this task.
If the barcode is found, the data array contains exactly 1 element. If not, it is empty and the function should return '-1'.
Use the "discount" and the "price" properties to calculate the discounted price rounded to the nearest integer.
discountedPrice = price - ((discount / 100) * price)
Function
getDiscountedPrice(barcode: String) → int
Complete the function getDiscountedPrice in the editor.
getDiscountedPrice has the following parameters:
string barcode: the item to query
Returns
int: the discounted price rounded to the nearest integer or -1
Constraints
- There will be either 1 or 0 records in data.
Examples
Example 1
barcode = "74002314"return = 2964https://jsonmock.hackerrank.com/api/inventory?barcode=74002314. The price = 3705 and discount = 20.Constraints
There will be either 1 or 0 records in dataMore Oracle problems
- Merge k Sorted ListsPHONE SCREEN · Seen Jul 2026
- Implement a Queue Using Two StacksPHONE SCREEN · Seen Jul 2026
- First Balanced Removal IndexOA · Seen Dec 2025
- Find Circle NumberSeen Oct 2024
- Create Lexicographically Largest PermutationSeen Sep 2024
- Array Reduction 1Seen Feb 2024
- Balancing ParenthesesSeen Feb 2024
- Merge 2 ArraysSeen Feb 2024