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 listOct 14, 2021 02:08Vitaliy F.Vitaliy F.Error
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 14, 2021 02:0800000Error: Exit with code 2: panic: runtime error: slice bounds out of range [142:141] goroutine 1 [running]: main.HackyParse.func1({0x7fbf6260029b, 0x91, 0x5635796a7e00}, {0xc000056ea1, 0xe, 0xe}, {0x5635795b815c, 0x3}, 0x81f, {0xc000056e8c, ...}, ...) ...stderr