Q1 A sports coach must ensure that two teams in a competition are equally strong. Teams A and B have n and m players. The players' skill levels are stored in arrays TeamA and TeamB. A 0 value indicates that the team lacks a player in that position. The coach wants to add players in each empty position such that the teams' skill levels have equal sums. Return the minimum possible equal sum or -1 if it is not possible to obtain such a sum.
Example
teamA = [5, 10, 0, 4]
teamB = [2, 4, 0, 5, 0]
Add a player of skill level 1 in teamA, and players of skill levels 3 and 6 in teamB. Now teamA = [5, 10, 1, 4], and teamB = [2, 4, 3, 5, 6], with sums 5+10+1+4 = 2+4+3+5+6 = 20
Function Description
Complete the function equalTeamSkill in the editor below.
equalTeamSkill has the following parameters:
int teamA[n]: skill levels of players
int teamB[m]: skill levels of playersReturns
int: an integer, which, if positive, denotes the minimum equal sum, and if -1 indicates that it is not possible to obtain an equal sumConstraints
1 ≤ n, m ≤ 105
0 ≤ teamA[i], teamB[i] ≤ 104
Input Format For Custom Testing
Sample Case 0
Sample Input For Custom Testing
STDIN FUNCTION
4 → teamA[] size n = 4
1 → teamA = [1, 2, 3, 0]
2
3
0
3 → teamB[] size n = 3
5 → teamB = [5, 0, 0]
0
0
Sample Output
7
Explanation
The final teams are teamA = [1, 2, 3, 1], and teamB = [5, 1, 1].
Q2 Use the HTTP GET method to retrieve information from a database of universities across the globe. Query https://jsonmock.hackerrank.com/api/universities 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 5 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 an array with a single object that contains the universities' records.
Example of a data array object:
"university": "King's College London",
"rank_display": "35",
"score": 82,
"type": "Public",
"student_faculty_ratio": 7,
"international_students": "15,075",
"faculty_count": "4,216",
"location": {
"city": "London",
"country": "United Kingdom",
"region": "Europe"
}
In data, each university has the following schema:
university: The name of the university (String)
rank_display: The rank of the university according to the 2022 QS Rankings (String).
score: The score of the university according to the 2022 QS Rankings (Number).
type: The type of university (String)
student_faculty_ratio: The ratio of number of students to the number of faculty. (Number)
international_students: The number of international students (String).
faculty_count: The number of faculty (String)
location: An object containing the location details. The object has the following schema:
city: (String)
country: (String)
region: (String)
Complete the highestInternationalStudents function where given the name of two cities as parameters, return the name of the university with the highest number of international students in the first city. If the first city does not have a university within the data, return the university with the highest number of international students in the second city.
Function Description
Complete the function highestInternationalStudents in the editor.
highestInternationalStudents has the following parameters:
string firstCity: name of the first city
string secondCity: name of the second cityReturns
string: the university with the highest number of international students.
Constraints
There is always a university in one of the two cities.
Note: Please review the header in the code stub to see available libraries for API requests in the selected language. Required libraries can be imported in order to solve the question. Check our full list of supported libraries at https://www.hackerrank.com/environment.
Sample Case 0
Sample Input For Custom Testing
Singapore
New York City
Sample Output
National University of Singapore (NUS)
Q3Given a number num, two adjacent digits can be swapped if their parity is the same, that is, both are odd or both are even. For example, (5, 9) have the same parity, but (6,9) do not.
Find the largest number that can be created. The swap operation can be applied any number of times.
Example
Let num = "7596801".
Swap 5 and 9 -> "7956801"
Swap 7 and 9 -> "9756801"
Swap 6 and 8 -> "9758601"
The largest value possible is "9758601".
Function Description
Complete the function getLargestNumber in the editor below.
getLargestNumber has the following parameter:
string num: a string of digitsReturns
string: the largest number that can be createdConstraints
1 ≤ length of num ≤ 105
num consists of digits 0-9 only.
Input Format For Custom Testing
Sample Case 0
Sample Input For Custom Testing
STDIN FUNCTION
0082663 → num = "0082663"
Sample Output
8662003
Explanation
Zero is even parity, so swaps can be made until the digits are arranged as shown.