Solved LeetCode program · 829 of 1,000
#1093 · Statistics from a Large Sample
Original English source
The counts is a list of 256 zeros. Set item 1 of counts to 1. Set item 2 of counts to 3. Set item 3 of counts to 4. The total is 0. The weighted is 0. The low is -1. The high is -1. The best is 0. The mode is 0.
For every value from 0 to 255.
The seen is item value of counts. If seen is more than 0 and low is less than 0, set low to value. If seen is more than 0, set high to value. Add seen to total. The contribution is seen times value. Add contribution to weighted. If seen is more than best, set best to seen, set mode to value.
The order is (total minus 1) divided by 2. The other is total divided by 2. The lower is 0. The upper is 0. The running is 0.
For every value from 0 to 255.
The seen is item value of counts. The before is running. Add seen to running. If order is at least before and order is less than running, set lower to value. If other is at least before and other is less than running, set upper to value.
Keep a shared rendered as empty text.
To render from scaled (a whole number). The parts is an empty list of text. The whole is scaled divided by 100000. The rest is scaled modulo 100000. The head is format whole number whole as text. Place head into parts. Place "." into parts. The remaining is rest.
For every slot from 0 to 4.
The unit is remaining divided by 10000. The digit is format whole number unit as text. Place digit into parts. Set remaining to (remaining modulo 10000) times 10. Set rendered to join parts with "".
The answers is an empty list of text. The lowscale is low times 100000. Render from lowscale. Place rendered into answers. The highscale is high times 100000. Render from highscale. Place rendered into answers. The meanscale is (weighted times 100000 plus total divided by 2) divided by total. Render from meanscale. Place rendered into answers. The medianscale is (lower plus upper) times 50000. Render from medianscale. Place rendered into answers. The modescale is mode times 100000. Render from modescale. Place rendered into answers.
The report is join answers with ",". Show report.
Expected stdout
1.00000,3.00000,2.37500,2.50000,3.00000