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:25Joad NacerJoad NacerScore: 7,866Success
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:255,110131,054,78656,206,56102,273,280
2Apr 18, 2024 22:255,117121,930,74056,290,92002,269,184
3Apr 18, 2024 22:255,152113,892,29856,673,17602,269,184
4Apr 18, 2024 22:257,860106,368,25685,455,0001,005,0002,269,184
5Apr 18, 2024 22:257,864109,376,04785,497,0001,005,0002,289,664
6Apr 18, 2024 22:257,864114,046,25785,503,0001,005,0002,289,664
7Apr 18, 2024 22:257,866109,177,01285,522,0001,006,0002,289,664
8Apr 18, 2024 22:257,867109,546,40985,527,0001,006,0002,289,664
9Apr 18, 2024 22:257,868110,480,92885,541,0001,006,0002,277,376
10Apr 18, 2024 22:257,868107,322,03085,543,0001,006,0002,289,664
11Apr 18, 2024 22:257,876116,245,04885,624,0001,007,0002,289,664
12Apr 18, 2024 22:257,880108,766,71185,675,0001,007,0002,523,136