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:18Joad NacerJoad NacerScore: 7,511Success
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:184,982111,965,80754,799,01802,260,992
2Apr 18, 2024 23:184,999142,897,21654,987,34902,277,376
3Apr 18, 2024 23:185,005114,408,11255,053,18902,277,376
4Apr 18, 2024 23:187,500104,572,85481,499,0001,006,0002,523,136
5Apr 18, 2024 23:187,501105,588,96582,512,00002,527,232
6Apr 18, 2024 23:187,509108,582,57081,591,0001,007,0002,289,664
7Apr 18, 2024 23:187,511116,066,27682,616,00002,289,664
8Apr 18, 2024 23:187,512112,882,47181,627,0001,007,0002,289,664
9Apr 18, 2024 23:187,513107,676,13581,631,0001,007,0002,289,664
10Apr 18, 2024 23:187,513106,891,23781,635,0001,007,0002,281,472
11Apr 18, 2024 23:187,527111,155,74881,796,000997,0002,531,328
12Apr 18, 2024 23:187,532110,927,11781,849,000998,0002,289,664