Belvedere TrainingSoftware Engineer - Entry Level 2024 Chicago
新人求加米 看面经~🙏🙏🙏
这家准备的时候在地里找不到太多信息和oa,尤其是找不到24的。于是就用地里找的往年的题(斐波那契,four corners, 一个算数的trading题,manufacturing problem,naive hedging algorithm这五道题)练的。但今年换了新题
平台: HireVue 不太好用,而且test cases给的很少。具体样子看下图。不要开cam
三道题,每交一题看下一题
Trade Aggregator 30min
Concert Ticket Exchange 60min
Opportunistic Stock Trading 60min
我感觉主要是考察oop,数据结构和算法都不是很难,但是题目描述比较复杂,还涉及一些trading的知识。
题目已经给了代码框架(一些func和struct)只用写几个函数之类的
第一题text有的乱码了可以结合最底下图一起看
如有帮助请加点米吧谢谢!
--------------------------------------------------------------------------------------------------------------
1Trade Aggregator
When a trader buys or sells an asset, that trade is said to have a certain amount of "edge" defined as the difference between the trade price and a theoretical value. Theoretical value is what the Trader or Firm thinks the asset is worth, and can change throughout the day.
Edge_{buy} = TheoreticalValue - TradePriceEdge
?buy
?? =TheoreticalValue?TradePrice Edge_{sell} = TradePrice - TheoreticalValueEdge
?sell
?? =TradePrice?TheoreticalValue
Traders typically want to execute trades that have positive edge, that is buying an asset for lower than the theoretical value, or selling an asset for higher than the theoretical value.
For example: TradePrice = 95, TheoreticalValue = 100, Edge = 100-95 = 5
As a Firm, we want to track which traders are making the best decisions, so we calculate a score for each trade.
Score = SignOfEdge(Edge^2 * {|Quantity|} )Score=SignOfEdge(Edge
?2
?? ?∣Quantity∣)
Notice that negative edge will result in a negative score, indicating a bad trade.
Task
Given a series of trades, print the trader with the highest cumulative score after each trade.
Additional Details
A "Buy" trade will have positive quantity, and "Sell" trades will be denoted by negative (-) quantity.
Theoretical Values can be updated periodically. Your solution should use the most recent theoretical value when calculating edge. If an asset does not have an available theoretical value at the time of trade, assume Edge = 0 and save the trade price as the theoretical value. Theo Updates are not retroactive, so any existing trade for that asset should NOT be updated
Trades may happen with negative edge. They are valid and should be included in a traders cumulative score.
If more than one trader has the highest cumulative score, use lexicographical ordering of TraderName to break the tie.
input:A number trade lines in the following format:
Trade <TraderName> <Asset> <Quantity> <Price>
Interlaced with 1 or more theo update lines in the following format:
TheoUpdate <Asset> <Value>
Example:
TheoUpdate 1 100
Trade Alice 1 1 95
Trade Bob 1 1 94
Trade Alice 1 -1 107
output:
A line of output for each trade in the input, in the format
<TraderName> <Score>
Example:
Alice 25
Bob 36
Alice 74
----------------------------------------------------------------------------------------------------------------------------
下载测试 1 输入
TheoUpdate 1 100
Trade Alice 1 1 95
Trade Bob 1 1 94
Trade Alice 1 -1 107
预期输出
Alice 25.00
Bob 36.00
Alice 74.00
下载测试 2 输入
TheoUpdate 1 100
Trade Alice 1 -2 101
Trade Bob 1 -2 99
预期输出
Alice 2.00
Alice 2.00
下载测试 3 输入
TheoUpdate 1 100
Trade Alice 1 400 99
Trade Bob 1 5 90
预期输出
Alice 400.00
Bob 500.00
下载测试 4 输入
TheoUpdate 1 100
TheoUpdate 2 200
Trade Alice 1 1 98
Trade Bob 2 1 199
预期输出
Alice 4.00
Alice 4.00
--------------------------------------------------------------------------------------------------------------------------------
2 Concert Ticket Exchange
Concert tickets can be hard to come by, especially when going through the resale market. We would like to build our own concert ticket exchange system so that we can view available tickets in real-time. This system will listen to incoming ticket orders for a new concert venue, BT Arena. We'd like to build a system that listens to concert ticket orders and provides fans with this market information in the form of a price ladder.
Concert ticket orders arrive as a stream of events that can either add an order to our market data book or delete an order from our book. We also want to be able to delete all orders at given price level.
Add orders come with the following information:
Action - ADD
OrderId - unique identifier for order
Artist - concert performer, such as "TaylorSwift" or "Drake"
Price - price for the order
Quantity - positive quantity is a buy order and negative quantity is a sell order
Delete orders come with the following information:
Action - DEL
Artist - concert performer, such as "TaylorSwift" or "Drake"
OrderId - Unique identifier for the order to be deleted
Delete price levels come with the following information:
Action - DEL_PRICE
Artist - concert performer, such as "TaylorSwift" or "Drake"
Price - price level to be deleted
We'd like to keep track of these events so that fans can request a market view in the form of a price ladder. A price ladder is made up of n price levels for buy orders and sell orders. A price level consists of the Price, BuyQuantity, and SellQuantity. A price level will either have a non-zero BuyQuantity or SellQuantity, but not both. For buy orders, the best price is the highest price because that is the price a ticket holder would sell at. Conversely, the best price for sell orders is the lowest price. The streamed events will guarantee at least n price levels for both buys and sells.
input:
Repeated number of order operations in the following format:
<ADD> <OrderId> <Artist> <Price> <Quantity>
<DEL> <OrderId> <Artist>
<DEL_PRICE> <Artist> <Price>
We can get orders for different artists in the same stream of operations. The last line of input will the artist and number of price levels that we would like to view in our ladder for both buy and sell orders.
<Artist> <NumriceLadder.GetPriceLevels(artist, numberOfPriceLevels);
}
}
}
第三题
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <exception>
#include <sstream>
#include <iomanip>
struct Bundle
{
std::string name;
double price;
int numComponents;
std::vector<std::pair<int, std::string>> components;
};
struct Stock
{
std::string name;
double price;
};
class MarketWatchPortfolio
{
private:
std::vector<Bundle> _bundles;
std::unordered_map<std::string, Stock> _stocks;
public:
MarketWatchPortfolio(std::vector<Bundle> const& bundles, std::unordered_map<std::string, Stock> const& stocks)
: _bundles(bundles), _stocks(stocks)
{}
void ExecuteTrades()
{
// TODO(candidate): implement logic here
}
private:
void PrintTrade(std::string const& symbol, std::string const& bundleOrIndividualStock, double cost)
{
std::cout << std::setprecision(2) << std::fixed;
std::cout << symbol << " E " << bundleOrIndividualStock << " " << cost << std::endl;
return;
}
void PrintNoTrade(std::string const& symbol)
{
std::cout << symbol << " P" << std::endl;
return;
}
};
class InputData
{
public:
int numBundles;
int numStocks;
MarketWatchPortfolio LoadInput()
{
std::vector<Bundle> bundles;
std::unordered_map<std::string, Stock> stocks;
std::string line;
int numStocks = -1;
int numBundles = -1;
while (std::getline(std::cin, line))
{
if (line.empty())
{
break;
}
std::stringstream ss;
ss << line;
if (numStocks == -1 && numBundles == -1)
{
ss >> numBundles >> numStocks;
continue;
}
if (numBundles > 0)
{
Bundle bundle{};
auto const& components = SplitString(line, " ");
bundle.name = components[0];
bundle.price = std::stod(components[1]);
bundle.numComponents = std::stoi(components[2]);
for (std::size_t i = 3; i < components.size() - 1; i = i + 2)
{
auto const& c = std::make_pair(std::stoi(components[i + 1]), components[i]);
bundle.components.push_back(c);
}
bundles.push_back(bundle);
numBundles--;
continue;
}
Stock stock;
ss >> stock.name >> stock.price;
stocks.emplace(stock.name, stock);
}
return MarketWatchPortfolio{ bundles, stocks };
}
private:
std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter)
{
std::vector<std::string> strs;
size_t startPos = 0;
size_t endPos = 0;
while ((endPos = str.find(delimiter, startPos)) != std::string::npos)
{
strs.emplace_back(str.substr(startPos, endPos - startPos));
startPos = endPos + 1;
}
strs.emplace_back(str.substr(startPos));
return strs;
}
};
int main()
{
InputData inputData;
auto portfolio = inputData.LoadInput();
portfolio.ExecuteTrades();
}
|