1
I have a situation that is as follows:
given an array with for example 5 positions [5, 10, 8, 2, 7]
I need an algorithm that allows me to do the following:
Take the 5 and subtract by the numbers that are after your position
[10, 8, 2, 7]
Take the 10 and subtract by the numbers that are after your position
[8, 2, 7]
Take 8 and subtract by the numbers that are after your position
[2, 7]
And so on. I need to store the result of these subtractions in a new array.
Can be in either of the two languages.
One thing to note is that this is not directly possible using a stack, unless the language/technology does not respect the concepts of the structure. If it is a college exercise or the like, it will be necessary to move the elements of this stack to another structure.
– Jéf Bueno