You have a phenomenon that produces strictly positive or negative results.
delta = [1 -3 4 2 -1 6 -2 -7];
Marching through this list from beginning to end, mark a value with -1 if it is the greatest magnitude negative yet seen (strictly greater, not equal). Mark it with a one if it has the greatest magnitude in the positive direction (strictly greater, not equal). Just use a 0 if neither of these conditions have been met.
The result for the above example would be:
result = [1 -1 1 0 0 1 0 -1]
The phrasing might be a bit ambiguous, as magnitude swing could also be thought of as delta(i-1)-delta(i) instead of just delta(i). Nonetheless fun problem!
Nice question.
Nice problem
Flawed solution; fails (for example) when 0<0.
Officially not correct because it assumes that the first entry of x is 1, which is true for all testcases
Flawed solution; fails when delta(1)<delta(1). (For example: when delta = [-2, 1, 3, -4, -5], or when delta = [4,3,2,1,-1].)
This is genius lololol
great solution Gwendolyn
Very nice the construct to avoid (for example) meshgrid!!
also the use of 'minus' to avois the use of double(...)-double(...)
Very interesting!
J.R.!
3307 Solvers
Number of 1s in the Binary Representation of a Number
319 Solvers
138 Solvers
263 Solvers
341 Solvers