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 22, 2021 06:15alex3dalex3dError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 22, 2021 06:0700000Error: exit with code 1: 1000000 199317 19% 267262650 267 i_cnt=83 c_cnt=89732 uid=0~9999 tuid=0~9999 amo=0~999 wtf0 1003 "user_id": 8278}# _id": 9621, "amount": 119}, {"amount": 485, "to_user_id": 21}], "user_id": 8278}stderr
2Jun 22, 2021 06:1000000Error: exit with code 1: 1000000 199923 19% 267097017 267 i_cnt=84 c_cnt=89824 uid=0~9999 tuid=0~9999 amo=0~999 wtf0 126 {"to_user_id": 7# ": 384, "to_user_id": 7864}, {"to_user_id": 125, "amount": 10}, {"to_user_id": 7stderr
3Jun 22, 2021 06:1562,414755,462,637686,556,41502,256,896
4Jun 22, 2021 06:1562,459753,436,154687,049,31402,265,088
5Jun 22, 2021 06:1562,512765,134,555687,627,41702,277,376