Write a Java program to find the maximum number inside the number in the window (size k) at each moving in a given array of integers with duplicate numbers. Move the window from the start of the array
Sample output:
{|1, 2, 3|, 4, 5, 6, 7, 8, 8} -> Return maximum 3
{1, |2, 3, 4|, 5, 6, 7, 8, 8} -> Return maximum 4
{1, 2, |3, 4, 5|, 6, 7, 8, 8} -> Return maximum 5
{1, 2, 3, |4, 5, 6|, 7, 8, 8} -> Return maximum 6
{1, 2, 3, 4, |5, 6, 7|, 8, 8} -> Return maximum 7
{1, 2, 3, 4, 5, |6, 7, 8|, 8} -> Return maximum 8
{1, 2, 3, 4, 5, 6, |7, 8, 8|} -> Return maximum 8
Result array {3, 4, 5, 6, 7, 8, 8}
Expected Output:
Original array: [1, 2, 3, 4, 5, 6, 7, 8, 8]
Value of k: 3
Result:
2
3
4
5
6
7
8
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer