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 13:05Joad NacerJoad NacerScore: 7,295Success
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 13:064,773111,183,98952,507,61902,273,280
2Apr 20, 2024 13:054,774113,578,99952,510,36302,256,896
3Apr 20, 2024 13:054,777112,580,01952,545,06802,269,184
4Apr 20, 2024 13:064,777128,924,08352,542,99402,273,280
5Apr 20, 2024 13:054,782126,672,98852,604,93702,273,280
6Apr 20, 2024 13:064,800112,567,11852,794,57902,256,896
7Apr 20, 2024 13:067,281106,416,45480,091,00002,289,664
8Apr 20, 2024 13:057,291103,695,09978,195,0002,005,0002,289,664
9Apr 20, 2024 13:067,292102,955,94378,205,0002,005,0002,269,184
10Apr 20, 2024 13:067,293101,635,40778,213,0002,005,0002,289,664
11Apr 20, 2024 13:067,295102,272,87478,234,0002,006,0002,289,664
12Apr 20, 2024 13:067,295106,222,72778,238,0002,006,0002,531,328
13Apr 20, 2024 13:067,295104,126,32478,235,0002,006,0002,289,664
14Apr 20, 2024 13:057,301104,504,73279,307,0001,003,0002,289,664
15Apr 20, 2024 13:057,302102,559,22078,318,0002,008,0002,281,472
16Apr 20, 2024 13:057,304105,824,23780,347,00002,269,184
17Apr 20, 2024 13:057,304104,409,04978,338,0002,008,0002,289,664
18Apr 20, 2024 13:057,306109,481,12180,366,00002,273,280
19Apr 20, 2024 13:067,311106,235,21880,418,00002,289,664
20Apr 20, 2024 13:057,313100,906,47980,443,00002,379,776
21Apr 20, 2024 13:067,316101,958,75579,467,0001,005,0002,289,664
22Apr 20, 2024 13:057,320106,992,13379,516,0001,006,0002,289,664
23Apr 20, 2024 13:067,322104,334,85079,534,0001,006,0002,289,664
24Apr 20, 2024 13:057,323102,740,02779,545,0001,006,0002,289,664