Parse JSON Sergey Svistunov

Compute the total amount of non-canceled external USD transactions from a stream of JSON records as fast as possible.

Input: 1 000 000 JSON records on STDIN, one per line. Each record has the following structure:

{
    "user_id": 0,
    "currency": "USD",
    "transactions": [
        {
            "amount": 0,
            "to_user_id": 0,
            "canceled": false
        }
    ]
}
Field Constraints
user_id Integer, max 10 000
currency One of "GBP", "USD", "RUB", "JPY", "CHF"
transactions Array, max 10 elements
amount Integer, max 1000
canceled Boolean; may be omitted when false

Field order is not guaranteed within any object.

Output: The total amount of all transactions where:

  • record.currency == "USD"
  • transaction.to_user_id != record.user_id (external)
  • transaction.canceled is false or absent
Back to listApr 18, 2024 23:53Joad NacerJoad NacerScore: 7,869Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 18, 2024 23:534,819106,708,01253,008,86502,252,800
2Apr 18, 2024 23:534,821105,332,15253,034,18402,269,184
3Apr 18, 2024 23:534,830110,831,66953,128,24002,256,896
4Apr 18, 2024 23:537,846108,512,32486,302,00002,289,664
5Apr 18, 2024 23:537,868115,536,36586,553,00002,527,232
6Apr 18, 2024 23:537,868110,986,44085,547,0001,006,0002,265,088
7Apr 18, 2024 23:537,869113,308,35385,548,0001,006,0002,289,664
8Apr 18, 2024 23:537,872116,853,02485,586,0001,006,0002,289,664
9Apr 18, 2024 23:537,875111,569,28485,617,0001,007,0002,289,664
10Apr 18, 2024 23:537,876114,581,51685,632,0001,007,0002,289,664
11Apr 18, 2024 23:537,886111,533,24085,747,000997,0002,289,664
12Apr 18, 2024 23:537,903110,104,60085,936,000999,0002,289,664