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

  • Home
  • SEARCH
  • 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 5966955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:52:24+00:00 2026-05-22T19:52:24+00:00

EDIT: This isn’t as trivial as you think. Consider the fact that each addition

  • 0

EDIT:

This isn’t as trivial as
you think. Consider the fact that each
addition of a new number pushes out an
old number from the linkedlist.

The solution doesn’t seem to be as
simple as keeping track of a min
number with a variable. What if the
minimum gets pushed out of the
linkedlist? Then what? How do you know
what the new min is?

I heard this interview question:

You have a fixed length linked list.

  • At time t=0, the linkedlist is filled
    with random numbers.

  • At each increment in time, one new
    number is fed into the head of the
    linkedlist, and one number is pushed
    out from the tail.

  • You are allowed only ONE traversal before the first time interval.

    • This means one traversal ever. Not once at every time t.
      .
  • O(1) storage.

Your task is to be able to return the min of the linkedlist at every time interation.

What is an algorithm that would be able to do this?


Interesting note:

Since there’s no information regarding time complexity, you are allowed to use sort operations. The only problem then is: sorting takes more than one iteration.

  • 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-22T19:52:25+00:00Added an answer on May 22, 2026 at 7:52 pm

    First,

    O(1) storage is not the same as an a single register. It means constant space usage.

    Second,

    I am going to call your LL a constant size queue (CSQ).

    When initializing your queue, also initialize a min-heap where all elements of the queue keep a reference (pointer) to the heap node corresponding to them.

    1 op on CSQ

    • Pop 1 element out in O(1) time of the CSQ.
    • Remove corresponding node from the min-heap in O(lg n) time.
    • Add corresponding element to the min-heap in O(lg n) time.
    • Push 1 element into the CSQ in O(1) time and mark a reference to the heap node added above.

    The above operations guarentee that the heap size will always remain in sync with the queue size –hence O(1). The heap can be constructed in a single travesal.

    Finding min

    Clearly O(1). Just return the head of the min heap.

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

Sidebar

Related Questions

EDIT: This question was initially too general, I think. So What I really need
Edit: this isn't to be a dynamic output, the output view structure is fixed.
EDIT: this works, but not sure why? $('button').each(function() { $(this).bind( click, function() { alert($(this).val());
This isn't the complete code, but it's the parts that are causing problems. I've
EDIT: This isn't happening because of the ajax call. I changed it to use
Edit: This problem was down to me passing the wrong view to the Touch
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
Edit This question has gone through a few iterations by now, so feel free

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.