18. Array Previous Less
From your initial array of integers, create a new array of integers.
Each integer, i, in your array will be compared with the integers that come before it.
The last number (from the left) that is smaller than integer i will take integer i's position in a new array.
If there are no smaller integers to the left of integer i, -1 will take its place in the new array.
Example: The array [3, 5, 2, 4, 5] will return [-1, 3, -1, 2, 4].
Click for further explanation on example
- 3 has nothing to the left of it, so -1 takes its place in the returned array
- 5 is larger than 3, so the second integer in the new array is 3
- There are no integers to the left of 2 that are smaller than it, so -1 takes its place in the new array
- 3 and 2 are both smaller than 4, however, 2 is the last from the left, so 2 is the fourth integer in the new array
- 3, 2 and 4 are all smaller than 5, however, 4 is the last from the left, so 4 is the last integer in the new array
Array of Integers: []
*Note: Numbers with decimal places will be rounded down