MikeM: First pass - counting ones, twos and threes, second pass - filling "sorted" array with right amount of right numbers
Yes )) poor candidates clogged by previous questions on sorting what not to do for the fun of the public, and the bubble, and inserts, and all combinations with exceptions
GaryKa: Yes )) poor candidates, too shackled by previous sorting questions, do what they do for the entertainment of the public, with bubbles, sampling and all sorts of combinations with exceptions
Whatever you need isn't complicated. Anything that is complicated is unnecessary!
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
About the clock:
4 minutes after the start flip 4 minutes after the start
after flipping in 4 mins 4 mins, in 7 mins 3 mins.
after another 3 minutes
in 4-minutes 1 min, in 7-minutes 0
turn over 7 minutes
in 4-minutes 1 min, in 7-minutes 7
after another minute.
4 minutes 0, 7 minutes 6
turn over the 7 minutes.
in 4-minutes 0, in 7-minutes 1
in another minute - the right time!
Here is a puzzle.
Sure, it's boring, but at interviews it works as an apotheosis of array sorting knowledge.)
So, a sorting problem
There is an array of N cells, in which units, twos and threes are placed in random order.
Build the best sorting algorithm.
I.e. only 3 choices of data?
First pass: count how many ones, how many twos and how many threes.
Second pass: we fill.
Total 2 passes.
First pass - counting ones, twos and threes, second pass - filling "sorted" array with right amount of right numbers
Yes )) poor candidates, too shackled by previous sorting questions, do what they do for the entertainment of the public, with bubbles, sampling and all sorts of combinations with exceptions
A simple (for programmers) question:
A+B=...
I.e. only 3 variants of data?
First pass: count how many ones, how many twos and how many threes.
Second pass: fill in.
Total 2 passes.
In one pass:
Create an empty copy of an array of the same size, initialise it with twos.
We go from the beginning of the array. If we encounter 1, we copy it from the beginning; if we encounter 3, we copy it from the end.