Question 1:
You work for an airline, and you've been tasked with improving the procedure for reserving and buying seats.
You have the table seats, which describes seats in the airplane. It has the following columns:
seat_no - The unique number of the seat;
status - The status of the seat (0 indicates free, 1 indicates reserved, and 2 indicates purchased);
person_id - The ID of the person who reserved/purchased this seat (0 if the corresponding status is 0).
You also have the table requests, which contains the following columns:
request_id - The unique ID of the request;
request - The description of the request (1 indicates reserve, 2 indicates purchase);
seat_no - The number of the seat that the person want to reserve/purchase;
person_id - The ID of the person who wants to reserve/purchase this seat.A person can reserve/purchase a free seat and can purchase a seat that they have reserved.
Your task is to return the table seats after the given requests have been performed.
Note: requests are applied from the lowest request_id; it's guaranteed that all values of seat_no in the table requests are presented in the table seats.
Example
For the given tables seats
seat_no
status
person_id
1
1
1
2
1
2
3
0
0
4
2
3
5
0
0
and requests
request_id
request
seat_no
person_id
1
1
3
4
2
2
2
5
3
2
1
1
the output should be
seat_no
status
person_id
1
2
1
2
1
2
3
1
4
4
2
3
5
0
0
The first request is completed because seat number 3 is free. The second request is ignored because seat number 2 is already reserved by another person. The third request is completed because seat number 1 was reserved by this person, so they can purchase it.
[execution time limit] 10 seconds (mysql)
[memory limit] 1 GB
Question 2:
You are given an API endpoint that shows data about purchases in the market. The prices for products are given in international currency, and you'll need to convert the price of the purchase to internal currency. But the market is changing very fast, so you need to find out the currency exchange rate in the market at the time of the purchase.
So your task is divided into 2 parts:
Using the provided REST API, get information about the purchase.
Using the market currency exchange, find the exchange rate for the purchase and convert the purchase price into internal currency.
For the first subtask, perform a GET request to receive a JSON-formatted response containing the product name, product price in the international currency, and timestamp when the purchase was made in the market, in the following format:
{
"productName": "product1",
"productPrice": 100,
"timestamp" : 1552122500
}For the second subtask you are given a table currency in a MySQL database that contains information about each market exchange rate change. The table contains the following columns:
timestamp, an integer column containing the timestamp of the change;
exchangeRate, an integer column containing the rate for converting international currency into internal.
For example, a row with timestamp = 1552122000 and exchangeRate = 20 means that starting from time 1552122000 (inclusively), each international currency unit can be converted to 20 internal currency units. So, if the purchase was made for 100 international units, you will need to pay 2000 internal currency units for the purchase.
Your task is to find the sum you need to pay, in internal currency units.
API credentials
API endpoint for the GET request: http://localhost/marketPurchase.
Database credentials
Host: db;
Username: test;
Password: empty (no password);
Database name: ri_db.
Note: if you are solving this task in JavaScript or TypeScript use the request module for HTTP calls and the mysql2 module for connecting to the database.
Note: if you are solving this task in C# use the WebClient module for HTTP calls.
Example
For the following table currency
timestamp
exchangeRate
1552122000
10
1552125600
20
1552129200
30
And the following response from the API
{
"productName": "product1",
"productPrice": 100,
"timestamp" : 1552122600
}1000 should be printed to the standart output.
The purchase was made at timestamp = 1552122600. According to the market currency table, the exchange rate had changed to 10 at timestamp = 1552122000. The next change happens at timestamp = 1552125600, but the purchase happened before this, so it was made with purchaseRate = 10, so the answer is 100 * 10 = 1000.
[execution time limit] 12 seconds (py3)
[memory limit] 1 GB
Question 3:
You are given a data.csv file in the /root/customers/ directory containing information about your customers.
It has the following columns:
ID,NAME,CITY,COUNTRY,CPERSON,EMPLCNT,CONTRCNT,CONTRCOST
where
ID: Unique id of the customer
NAME: Official customer company name
CITY: Location city name
COUNTRY: Location country name
CPERSON: Email of the customer company contact person
EMPLCNT: Customer company employees number
CONTRCNT: Number of contracts signed with the customer
CONTRCOST: Total amount of money paid by customer (float in format dollars.cents)
Read and analyze the data.csv file, and output the answers to these questions:
How many total customers are in this data set?
How many customers are in each city?
How many customers are in each country?
Which country has the largest number of customers' contracts signed in it? How many contracts does it have?
How many unique cities have at least one customer in them?
The answers for second and third questions (the number of customers in each city and in each country) must be sorted by city and country name respectively, in ascending order. If there are several cities that are tied for having the most customers' contracts, print the alphabetically larger one. Please keep in mind that all string comparisons should be considered case-sensitive.
The answers should be formatted as:
Total customers:
<number>
Customers by city:
<CITY>: <number>
<CITY>: <number>
...
Customers by country:
<COUNTRY>: <number>
<COUNTRY>: <number>
...
Country with the largest number of customers' contracts:
<country> (<number> contracts)
Unique cities with at least one customer:
<number>Example
For the following data.csv
ID,NAME,CITY,COUNTRY,CPERSON,EMPLCNT,CONTRCNT,CONTRCOST
00000001,Breadpot,Sydney,Australia,Sam.Keng@info.com,250,48,1024.00
00000002,Hoviz,Manchester,UK,harry.ham@hoviz.com,150,7,900.00
00000003,Hoviz,London,UK,hamlet.host@hoviz.com,1500,12800,10510.50
00000004,Grenns,London,UK,grenns@grenns.com,200,12800,128.30
00000005,Magnolia,Chicago,USA,man@info.com,1024,25600,512000.00
00000006,Dozen,San Francisco,USA,dozen@dozen.com,1000,5,1000.20
00000007,Sun,San Francisco,USA,sunny@sun.com,2000,2,10000.01
the output for this should be:
Total customers:
7
Customers by city:
Chicago: 1
London: 2
Manchester: 1
San Francisco: 2
Sydney: 1
Customers by country:
Australia: 1
UK: 3
USA: 3
Country with the largest number of customers' contracts:
USA (25607 contracts)
Unique cities with at least one customer:
5Note that both USA and UK have the same number of contracts - 25607, but USA is alphabetically larger, so it is the answer.
[execution time limit] 7 seconds (py3)
[memory limit] 1 GB