Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7523591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:51+00:00 2026-05-30T02:50:51+00:00

Given an array of N elements, A[0 .. N – 1] , Produce an

  • 0

Given an array of N elements, A[0 .. N - 1], Produce an array B such that:

 B[i] = min (A[i], A[i+1], ..., A[i+K-1]). 

(The array B will have exactly (N-k+1) elements.

Time complexity should be better than O(N*k)

I was thinking of using minheap… but heapify will increase the complexity
Also brute force is O(n*k)

Also space complexity s’d be less than equal to O(k)

Here’s an example

Input: 
A={ 2,1,3,2,5,7,1}, N=7,k=3

Output:
B={1,1,2,2,1}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:50:54+00:00Added an answer on May 30, 2026 at 2:50 am

    To solve the problem, you can use queue in which push_rear(), pop_front() and get_min() are all constant time operations.

    Push first k elements from the array A to this queue. Then continue filling the queue from the array A, while popping elements from it and appending minimum values to the array B.

    Time complexity is O(N). Space complexity is O(k).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have seen a few days ago such problem there is given two array
Given an array of integers ,You have to find two elements whose XOR is
Suppose that you're given an array A of n distinct elements drawn from some
Given you have an array A[1..n] of size n, it contains elements from the
I have an array of 50+ elements that dictates how many hours were worked
Given an array with N elements. We know that one of those elements repeats
Given an array. How can we find sum of elements in index interval (i,
I have a string. I need to replace all instances of a given array
Given an array of ids $galleries = array(1,2,5) I want to have a SQL
Consider the following problem. We are given an array of elements belonging to one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.