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 listJul 27, 2024 11:11Joad NacerJoad NacerScore: 7,166Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 11:114,700123,179,15451,704,51702,285,568
2Jul 27, 2024 11:114,707103,819,78451,771,88402,277,376
3Jul 27, 2024 11:114,720111,701,14851,921,82102,277,376
4Jul 27, 2024 11:117,148103,773,86978,625,00002,535,424
5Jul 27, 2024 11:117,166107,080,88776,831,0001,995,0002,428,928
6Jul 27, 2024 11:117,166101,030,29378,827,00002,273,280
7Jul 27, 2024 11:117,166109,276,95877,834,000997,0002,535,424
8Jul 27, 2024 11:117,167104,336,55477,842,000997,0002,437,120
9Jul 27, 2024 11:117,173100,997,34377,909,000998,0002,428,928
10Jul 27, 2024 11:117,184101,297,27078,021,0001,000,0002,535,424
11Jul 27, 2024 11:117,186106,038,07378,048,0001,000,0002,535,424
12Jul 27, 2024 11:117,204105,403,10278,240,0001,003,0002,428,928