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 22:18Joad NacerJoad NacerScore: 7,963Success
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 22:185,127116,675,63456,401,75202,269,184
2Apr 18, 2024 22:185,134115,088,49256,477,97302,277,376
3Apr 18, 2024 22:185,159108,644,55556,748,57302,252,800
4Apr 18, 2024 22:187,953113,713,53287,478,00002,289,664
5Apr 18, 2024 22:187,954108,317,99686,493,0001,005,0002,523,136
6Apr 18, 2024 22:187,959110,855,84485,556,0001,989,0002,289,664
7Apr 18, 2024 22:187,963114,581,46686,589,0001,006,0002,527,232
8Apr 18, 2024 22:187,964118,408,90186,597,0001,006,0002,273,280
9Apr 18, 2024 22:187,966113,493,77286,624,0001,007,0002,285,568
10Apr 18, 2024 22:187,968121,070,55186,640,0001,007,0002,289,664
11Apr 18, 2024 22:187,970114,813,16985,676,0001,992,0002,273,280
12Apr 18, 2024 22:187,982113,855,25385,806,0001,995,0002,289,664