Snapshot Codec
You are given \(N\) L2 order book snapshots. Write an encoder and decoder to compress/uncompress the given data.
Solution format
Implement class Encoder/Decoder in the following way:
class Encoder {
public:
Encoder() = default;
std::string operator()(std::string_view);
};
class Decoder {
public:
Decoder() = default;
std::string operator()(std::string_view);
};
Input and Codec Specification
Encoder receives raw snapshots as std::string_view on valid JSON, the data is guaranteed to be collected from Binance Futures DepthSnapshot 20 levels stream via official websocket endpoint, we strongly recommend you to research the data locally.
Decoder receives all data produced by the Encoder in the same order.
Both codecs must return a std::string of encoded/decoded data with using only writable symbols (ASCII code 32–126).
After decoding encoded input the result must be exactly the same string as the provided input.
Number of bytes in input \(\le 2 * 10^7\)
Your output size for one snapshot may exceed the number of bytes in input. The total output size for each testcase must not be greater than input size.
Each test case is represented by two cases: encode and decode. For example test 1 is encoding sample, test 2 is decoding your output for test 1.
Scoring
Score for a test case is the total number of bytes saved by the Encoder.
Submission score is sum of scores of all test cases.
Participants are ranked by score in non-decreasing order.
Sample Input
{"e":"depthUpdate","E":1761838079877,"T":1761838079874,"s":"ETHUSDT","U":9034234411260,"u":9034234415746,"pu":9034234411215,"b":[["3781.70","11.286"],["3781.69","0.244"],["3781.68","16.577"],["3781.67","0.006"],["3781.66","0.006"],["3781.65","1.038"],["3781.64","0.011"],["3781.63","0.017"],["3781.62","1.361"],["3781.61","1.496"],["3781.60","0.034"],["3781.59","0.006"],["3781.58","0.011"],["3781.57","0.046"],["3781.56","0.017"],["3781.55","0.013"],["3781.54","0.021"],["3781.53","1.060"],["3781.52","0.007"],["3781.51","0.023"]],"a":[["3781.71","180.853"],["3781.72","0.978"],["3781.73","0.712"],["3781.74","0.032"],["3781.75","0.662"],["3781.76","0.006"],["3781.77","0.135"],["3781.78","0.032"],["3781.79","0.006"],["3781.80","0.030"],["3781.82","0.694"],["3781.83","0.017"],["3781.84","1.392"],["3781.86","0.043"],["3781.87","0.668"],["3781.88","0.011"],["3781.90","0.049"],["3781.91","0.006"],["3781.92","0.013"],["3781.93","2.574"]]}
{"e":"depthUpdate","E":1761838079905,"T":1761838079905,"s":"BTCUSDT","U":9034234414354,"u":9034234417973,"pu":9034234414248,"b":[["107842.00","1.937"],["107841.90","0.036"],["107841.30","0.002"],["107840.90","0.052"],["107840.70","0.002"],["107840.60","0.001"],["107840.50","0.005"],["107840.00","0.002"],["107839.80","0.004"],["107839.60","0.009"],["107839.50","0.003"],["107839.40","0.078"],["107839.20","0.002"],["107839.00","0.001"],["107838.90","0.002"],["107838.70","0.005"],["107838.60","0.002"],["107838.50","0.001"],["107838.40","0.480"],["107838.30","0.001"]],"a":[["107842.10","7.801"],["107842.20","0.010"],["107842.30","0.694"],["107842.40","0.042"],["107842.80","0.002"],["107842.90","0.002"],["107843.50","0.139"],["107843.70","0.002"],["107843.90","0.002"],["107844.00","0.725"],["107844.10","0.093"],["107844.50","0.002"],["107844.60","0.003"],["107845.00","0.003"],["107845.10","0.004"],["107845.60","0.003"],["107845.70","0.002"],["107846.20","0.139"],["107846.30","0.185"],["107846.40","0.006"]]}
{"e":"depthUpdate","E":1761838079910,"T":1761838079904,"s":"XRPUSDT","U":9034234414623,"u":9034234417909,"pu":9034234414314,"b":[["2.4653","41943.7"],["2.4652","323.9"],["2.4651","6908.4"],["2.4650","32616.8"],["2.4649","772.9"],["2.4648","3783.7"],["2.4647","5451.1"],["2.4646","14588.1"],["2.4645","22922.2"],["2.4644","5913.7"],["2.4643","10131.0"],["2.4642","7087.0"],["2.4641","39723.5"],["2.4640","53943.1"],["2.4639","53442.5"],["2.4638","4760.4"],["2.4637","13749.7"],["2.4636","6313.2"],["2.4635","17388.5"],["2.4634","10673.5"]],"a":[["2.4654","53239.2"],["2.4655","12840.7"],["2.4656","14133.5"],["2.4657","11548.8"],["2.4658","15577.6"],["2.4659","10470.0"],["2.4660","31050.6"],["2.4661","17687.3"],["2.4662","6673.2"],["2.4663","15545.2"],["2.4664","57686.5"],["2.4665","4888.6"],["2.4666","17676.9"],["2.4667","5041.7"],["2.4668","11332.5"],["2.4669","6496.0"],["2.4670","66350.4"],["2.4671","30991.5"],["2.4672","21302.4"],["2.4673","25913.9"]]}
Comments