REST API: Discounted Price
Updated
Problem 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).- Some fields that are not of interest.
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 Description 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
Function
getDiscountedPrice(barcode: String) → intExamples
Example 1
barcode = "74002314"return = 2964First, a call is made to API https://jsonmock.hackerrank.com/api/inventory?barcode=74002314. The price = 3705 and discount = 20.
Constraints
- There will be either 1 or 0 records in data.
More Oracle interview questions
- Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
- Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
- Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
- Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
- Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026
- Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
- Cache an Expensive Service Across ThreadsONSITE INTERVIEW · Seen Oct 2026
- Island Count and Maximum AreaONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Streaming AverageXantium · PHONE SCREEN
- Accumulate Numeric Value ObjectsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Real-Time Temperature Window StatisticsGoogle · ONSITE INTERVIEWGoogle interview questions
- Pro-Rata Order BookIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Stock System with Updates and Percentage ChangeLead Bank · ONSITE INTERVIEWLead Bank interview questions
- Equity Price History with O(1) StatisticsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- In-Memory URL ShortenerRevolut · PHONE SCREENRevolut interview questions
- Shuffle With Given Random DrawsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions