Download the Guru IA app

Android and iOS

Foto de perfil

Thiago

Análise de Algoritmos11/15/2024

A graph with the adjacent points is represented as an array,...

A graph with the adjacent points is represented as an array, yCoordinates, such that the array index represents the x-coordinate and the corresponding the element represents the Y-coordinate. Formally, each point (x, y) is represented as (i, yCoordinates[i]), where 0≤ i< n Find the number of increasing segments that span exactly k consecutive X-coordinates.

Notes:

A segment of the graph is said to be increasing if, for any two points (x1,y1) and (x2,y2) the value of (y2-y1)/(x2-x1) is positive. If the value of k is 1, each point is an increasing segment

Example yCoordinates = [6,5,7,8,10] k = 3

in this case, there are two increasing segments: formed by points (1,5), (2,7), (3,8) formed by points (2,7), (3,8), (4,10)

Any two points in these segments from an increasing segment, and each of these segments spans exactly 3 consecutive X-coordinates. Since tere are two increasing segments, the answer is 2

/* * Complete the 'countIncreasingSegments' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER_ARRAY yCoordinates * 2. INTEGER k */

public static int countIncreasingSegments(List<Integer> yCoordinates, int k) {
// Write your code here

}

}

Send your questions through the App
Google Play
App Store
Equipe Meu Guru

Do you prefer an expert tutor to solve your activity?

  • Receive your completed work by the deadline
  • Chat with the tutor.
  • 7-day error guarantee