Question: Write a pseudocode, A subarray is called alternating if any two consecutive numbers in it have opposite signs (i.e. one of them should be negative,
Write a pseudocode,
A subarray is called alternating if any two consecutive numbers in it have opposite signs (i.e. one of them should be negative, whereas the other should be positive). Given an array of n integers, write a pseudocode to compute for each index i, the length of the longest alternating subarray starting at i. For example:
input : a[] = {1, -5, 1, -5} output : For index 0, {1, -5, 1, -5} = 4 index 1, {-5, 1, -5} = 3 index 2, {1, -5} = 2 index 3, {-5} = 1. Input :a[] = {-5, -1, -1, 2, -2, - 3} Output : index 0, {-5} = 1 index 1, {-1} = 1 index 2, {-1, 2, -2} = 3 index 3, { 2, -2} = 2 index 4, {-2} = 1 index 5, {-3} = 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
