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:18Sergey StreminSergey StreminScore: 6,408Success
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:186,389134,701,17070,277,55302,187,264
2Nov 10, 2021 20:186,38996,821,82368,276,0002,008,0002,359,296
3Nov 10, 2021 20:186,396140,344,30970,354,92902,191,360
4Nov 10, 2021 20:186,402130,503,08870,422,42002,195,456
5Nov 10, 2021 20:186,40496,793,25370,440,00002,293,760
6Nov 10, 2021 20:186,40493,392,90869,435,0001,006,0002,293,760
7Nov 10, 2021 20:186,40894,149,73269,486,0001,007,0002,293,760
8Nov 10, 2021 20:186,41294,391,04169,523,0001,007,0002,293,760
9Nov 10, 2021 20:186,41295,224,07370,533,00002,502,656
10Nov 10, 2021 20:186,42097,981,14469,609,0001,008,0002,293,760
11Nov 10, 2021 20:186,420102,121,14069,614,0001,008,0002,293,760
12Nov 10, 2021 20:186,424102,079,45969,654,0001,009,0002,359,296