Count Sign Changes
The array has no zeros. Count how many times the sign flips from one item to the next, meaning a positive item followed by a negative one or a negative item followed by a positive one. Return an int.
Example 1
balance_changes [3,-1,-2,4,5,-6]
returns 3
The signs flip between 3 and -1, between -2 and 4, and between 5 and -6.
Constraints
1 <= len(balance_changes) <= 100- No item is 0
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Drop Lowest AverageEasy
- Empty SeatsEasy
- Fill MissingEasy
- First Day Over LimitEasy
- Full ColumnsEasy
- Good ColumnsEasy
- Group MaximumsEasy
- Is SortedEasy