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 20, 2024 17:28Joad NacerJoad NacerScore: 5,047Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 20, 2024 17:284,964115,201,69754,603,86302,269,184
2Apr 20, 2024 17:284,965137,701,77954,616,40102,277,376
3Apr 20, 2024 17:284,978120,417,94254,760,30102,269,184
4Apr 20, 2024 17:285,03778,877,59754,403,0001,007,0002,289,664
5Apr 20, 2024 17:285,04176,395,89154,444,0001,008,0002,289,664
6Apr 20, 2024 17:285,04175,340,04854,445,0001,008,0002,289,664
7Apr 20, 2024 17:285,04781,711,76055,518,00002,289,664
8Apr 20, 2024 17:285,05181,497,01955,564,00002,289,664
9Apr 20, 2024 17:285,05376,711,76154,587,000992,0002,383,872
10Apr 20, 2024 17:285,05582,396,79155,600,00002,289,664
11Apr 20, 2024 17:285,05887,390,67554,623,0001,011,0002,289,664
12Apr 20, 2024 17:285,07787,646,05553,853,0001,994,0002,289,664