The TransCompilator

Solved LeetCode program · 863 of 1,000

#1169 · Invalid Transactions

Medium Array chunk-18.md

Original English source

The records is a list of "alice,20,800,mtv", and "alice,50,100,beijing". The names is an empty list of text. The times is an empty list of whole numbers. The amounts is an empty list of whole numbers. The cities is an empty list of text. The invalid is an empty list of whole numbers. The lastrecord is the last position of records.
For each record in records.
The parts is split record by ",". The name is item 0 of parts. The timepiece is item 1 of parts. The amountpiece is item 2 of parts. The city is item 3 of parts. The time is the digit value of character 0 of timepiece. The digit is 0. If the length of timepiece is more than 1, Set digit to the digit value of character 1 of timepiece, Set time to time times 10 plus digit. If the length of timepiece is more than 2, Set digit to the digit value of character 2 of timepiece, Set time to time times 10 plus digit. If the length of timepiece is more than 3, Set digit to the digit value of character 3 of timepiece, Set time to time times 10 plus digit. The amount is the digit value of character 0 of amountpiece. If the length of amountpiece is more than 1, Set digit to the digit value of character 1 of amountpiece, Set amount to amount times 10 plus digit. If the length of amountpiece is more than 2, Set digit to the digit value of character 2 of amountpiece, Set amount to amount times 10 plus digit. If the length of amountpiece is more than 3, Set digit to the digit value of character 3 of amountpiece, Set amount to amount times 10 plus digit. Place name into names. Place time into times. Place amount into amounts. Place city into cities. Place 0 into invalid.

For every left from 0 to lastrecord.
If item left of amounts is more than 1000, set item left of invalid to 1.
For every right from 0 to lastrecord.
The gap is item left of times minus item right of times. Set gap to the absolute value of gap. The samecity is 0. The samename is 0. If item left of cities matches item right of cities, set samecity to 1. If item left of names matches item right of names, set samename to 1. If left is not right and samename is 1 and samecity is 0 and gap is at most 60, set item left of invalid to 1.

For every left from 0 to lastrecord.
If item left of invalid is 1, Show item left of records.

Open in Playground Browse all 1,000 problems

Expected stdout

alice,20,800,mtv
alice,50,100,beijing