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,900Success
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,832116,366,51153,156,48402,269,184
2Apr 18, 2024 23:534,845109,108,57853,289,87402,260,992
3Apr 18, 2024 23:534,854120,127,94353,390,98202,260,992
4Apr 18, 2024 23:537,865112,100,61885,505,0001,005,0002,523,136
5Apr 18, 2024 23:537,872115,294,62585,581,0001,006,0002,523,136
6Apr 18, 2024 23:537,891111,638,22185,808,000997,0002,289,664
7Apr 18, 2024 23:537,900111,624,51284,905,0001,997,0002,289,664
8Apr 18, 2024 23:537,905115,039,94785,958,000999,0002,531,328
9Apr 18, 2024 23:537,907110,882,37885,981,000999,0002,289,664
10Apr 18, 2024 23:537,919114,474,32085,105,0002,002,0002,289,664
11Apr 18, 2024 23:537,932111,343,24786,247,0001,002,0002,289,664
12Apr 18, 2024 23:537,937111,129,67986,305,0001,003,0002,269,184