[IBM] OA 2025 Start – 18 Feb (Generic)
  1. Question 1

Students in a class are asked to stand in ascending order according to their heights for the annual class photograph. Determine the number of students not currently standing in their correct positions.

Example
height = [1, 1, 3, 3, 4, 1]

The 3 students indicated in red at indices 2, 4 and 5, are not in the right positions. The correct positions are [1, 1, 1, 3, 3, 4].

Function Description

Complete the function countStudents in the editor below.

countStudents has the following parameter(s):

  • int height[n]: an array of heights in the order the students are standing

Returns:

  • int: the number of students not standing in the correct positions.

Constraints

  • 1 ≤ n ≤ 10⁵
  • 1 ≤ height[i] ≤ 10⁹

  1. Question 2

Use the HTTP GET method to retrieve information from a database of restaurant information. Query
https://jsonmock.hackerrank.com/api/food_outlets?city=<city>
to find all the records. The query result is paginated and can be further accessed by appending to the query string &page=<num> where num is the page number.

The response is a JSON object with the following five fields:

  • page: The current page of the results. (Number)
  • per_page: The maximum number of results returned per page. (Number)
  • total: The total number of results. (Number)
  • total_pages: The total number of pages with results. (Number)
  • data: Either an empty array or one that contains the food outlet records.

In data, each food outlet has the following schema:

  • id: outlet id (Number)
  • name: The name of the outlet (String)
  • city: The city in which the outlet is located (String)
  • estimated_cost: The estimated cost of the food in the particular outlet (Number)
  • user_rating: An object containing the user ratings in the following schema:
    • average_rating: The average user rating for the outlet (Number)
    • votes: The number of people who voted for the outlet (Number)

Given the function arguments city and cost, find the food outlet in the city that has the highest rating and whose estimated_cost is at most cost. If there are multiple restaurants that tie for the highest rating, return the one with the lowest expected cost.

Function Description

Complete the function bestRestaurant in the editor below.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

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