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 listJun 19, 2021 16:02alex3dalex3dError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 19, 2021 16:0200000Error: exit with code 1: {"transactions": [{"to_user_id": 8564, "amount": 101}, {"to_user_id": 6366, "amount": 422}, {"to_user_id": 4817, "amount": 594}, {"amount": 400, "to_user_id": 9531}, {"canceled": false, "to_user_id": 2016, "amount": 914}, {"to_...stderr
2Jun 19, 2021 16:0800000Error: exit with code 1: {"currency": "RUB", "transactions": [{"canceled": false, "amount": 654, "to_user_id": 9127}, {"canceled": true, "amount": 143, "to_user_id": 1466}, {"canceled": true, "to_user_id": 8979, "amount": 630}, {"amount": 490, "to_user...stderr
3Jun 19, 2021 16:0800000Error: exit with code 1: {"user_id": 7038, "currency": "JPY", "transactions": [{"canceled": false, "amount": 701, "to_user_id": 2206}, {"amount": 535, "to_user_id": 262}, {"to_user_id": 8700, "amount": 376}, {"to_user_id": 4035, "amount": 853, "cancele...stderr
4Jun 19, 2021 16:0800000Error: exit with code 1: {"transactions": [{"amount": 483, "to_user_id": 4134, "canceled": false}, {"to_user_id": 1619, "amount": 197}, {"amount": 565, "canceled": false, "to_user_id": 4187}, {"to_user_id": 7098, "amount": 309}], "currency": "RUB", "us...stderr