Knowee
Questions
Features
Study Tools

iven an array of numbers and a window of size k. Print the maximum of numbers inside the window for each step as the window moves from the beginning of the array.Input FormatInput contains the array size, no of elements and the window sizeOutput FormatPrint the maximum of numbersConstraints1 <= size <= 1000                    Sample Input 181 3 5 2 1 8 6 93

Question

iven an array of numbers and a window of size k. Print the maximum of numbers inside the window for each step as the window moves from the beginning of the array.Input FormatInput contains the array size, no of elements and the window sizeOutput FormatPrint the maximum of numbersConstraints1 <= size <= 1000                    Sample Input 181 3 5 2 1 8 6 93

🧐 Not the exact question you are looking for?Go ask a question

Solution

The problem is asking to find the maximum number in each subarray of size k in the given array. Here are the steps to solve this problem:

  1. Initialize an empty list to store the maximum numbers.
  2. Iterate over the array from the 0th index to the (n-k+1)th index, where n is the size of the array. For each iteration:
    • Extract the subarray of size k starting from the current index.
    • Find the maximum number in this subarray.
    • Append this maximum number to the list.
  3. Print the list of maximum numbers.

Here is a Python solution for the problem:

def print_max(arr, n, k):
    max_nums = []
    for i in range(n-k+1):
        max_nums.append(max(arr[i:i+k]))
    print(max_nums)

# Test the function
print_max([1, 3, 5, 2, 1, 8, 6, 9], 8, 3)

This will output: [5, 5, 5, 8, 8, 9], which are the maximum numbers in each subarray of size 3.

This problem has been solved

Similar Questions

Distinct Elements in WindowMax Score: 100Given an array of integers and a window size K, find the number of distinct elements in every window of size K of the given array.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines. The first line of each test case contains the N-size of the array and the K-size of the window. The second line contains N integers - elements of the array.Output FormatFor each test case, print the number of distinct elements in every window of size K, separated by a new line.Constraints30 points1 <= N <= 1001 <= K <= N70 points1 <= N <= 100001 <= K <= NGeneral Constraints1 <= T <= 1000-100 <= ar[i] <= 100ExampleInput35 3-2 -4 -2 4 -210 73 -4 -3 -4 -2 0 2 -2 6 017 13-5 -1 4 8 -5 -3 -4 7 4 -4 0 8 0 -2 3 2 5Output2 3 26 5 6 58 9 9 10 11ExplanationSelf Explanatory

Given an array of integers, find the largest number that can be constructed by concatenating all the elements of the given array.Input FormatFirst line of input contains T - number of test cases. Its followed by 2T lines. First line of each test case contains N - size of the array and the second line contains N integers - elements of the array.Constraints1 <= T <= 10001 <= N <= 10000 <= ar[i] <= 1000Output FormatFor each test case, print the largest number that can be constructed by concatenating all the elements of the given array, separated by newline.Sample Input 03849 73 58 30 72 44 78 23 469 9 57 60 240 4 Sample Output 078737258494430239696057440

You have been given an array 'A' of N integers. You need to find the maximum value of j - i subjected to the constraint of A[i] <= A[j], where ‘i’ and ‘j’ are the indices of the array.For example :If 'A' = {3, 5, 4, 1}then the output will be 2.Maximum value occurs for the pair (3, 4)Detailed explanation ( Input/output format, Notes, Images )Constraints:1 <= T <= 1001 <= N <= 10 ^ 4-10 ^ 5 <= A[i] <= 10 ^ 5Time limit: 1 sec.Sample Input 1:1934 8 10 3 2 80 30 33 1Sample Output 1:6Explanation:Maximum value occurs for the pair (8, 33)Sample Input 2:1109 2 3 4 5 6 7 8 18 0Sample Output 2:8Explanation:Maximum value occurs for the pair (9, 18)

Given two arrays (arr1[], arr2[]) of integers, display the largest number in arr1, where that element should not be present in arr2. If the constraint is not satisfied return 0.Variable Constraints:Size of the array <= 5;Array data type = integer.Input Size of array 1Elements of array 1Size of array 2Elements of array 2OutputLargest element in array 1

ai is creating a program to find the maximum number from the given two integers using pointers.Help him with the task.Input format :The input consists of two space-separated integers.Output format :The output prints the maximum number.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ input integers ≤ 100Sample test cases :

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.