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 listNov 10, 2021 20:32Sergey StreminSergey StreminScore: 5,221Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Nov 10, 2021 20:325,19377,436,94855,119,0002,004,0002,293,760
2Nov 10, 2021 20:325,19983,836,60755,188,0002,006,0002,293,760
3Nov 10, 2021 20:325,20683,135,56855,261,0002,009,0002,293,760
4Nov 10, 2021 20:325,21579,858,10956,362,0001,006,0002,293,760
5Nov 10, 2021 20:325,21879,999,97657,400,00002,363,392
6Nov 10, 2021 20:325,21885,276,84856,396,0001,007,0002,293,760
7Nov 10, 2021 20:325,221115,317,73657,434,24402,187,264
8Nov 10, 2021 20:325,22780,009,74556,488,0001,008,0002,363,392
9Nov 10, 2021 20:325,23079,509,59356,520,0001,009,0002,293,760
10Nov 10, 2021 20:325,232116,463,64157,549,20502,195,456
11Nov 10, 2021 20:325,237120,920,58157,610,18002,199,552
12Nov 10, 2021 20:325,23786,264,33156,601,0001,010,0002,359,296