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 644391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:23:08+00:00 2026-05-13T21:23:08+00:00

Is there any well-known algorithm (or obvious solution) for transforming a list from order

  • 0

Is there any well-known algorithm (or obvious solution) for transforming a list from order A to order B using only push and remove operations? For instance, from a b c d to b c a d could be done using the following operations:

remove(a)
remove(d)
push(a)
push(d)

Or, from c b a to a b would be

remove(c)
remove(b)
push(b)

Or, from a c b to a c b d would be

push(d)

Here, push appends an element to the end of the list, and remove removes the element and shifts the subsequent elements so that the list is always in continuous state (no “empty slots”). Additionally there’s a condition that at any given moment the list may contain the same element only once. Therefore it seems sound to first do all removes in one bunch, and all pushes after that. The order of removes obviously doesn’t matter, but the order of pushes does.

A trivial solution would be to first remove all elements and then push the desired elements in the desired order. But since I know that most of the time the transforms will be quite small, equivalent to single pushes orremoves, I want to “reuse” any existing correct order in the list (for instance, transforming abcdef to abcde would require just one remove operation – quite a difference to the alternative (6+5 operations)). So, how to come up with the right (minimum) set of removes and list of pushes?

  • 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-13T21:23:09+00:00Added an answer on May 13, 2026 at 9:23 pm

    From what I can tell, you are going to be removing from anywhere and pushing to the back.

    Because you can’t insert into the middle of the list, the only way you can minimize the number of operations is to go through the list linearly and remove any element that is not correct.

    i.e. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 2, 4, 6, 7, 8, 13, 14

    1. compare 1
      1. remove 1
    2. compare 2
    3. compare 3
      1. remove 3
    4. compare 4
    5. compare 5
      1. remove 5
    6. compare 6
    7. compare 7
    8. compare 8
    9. compare 9
      1. remove 9
    10. compare 10
      1. remove 10
        (reached end)
    11. push 13
    12. push 14

    If your push wasn’t so limited, there would be more efficient ways of doing this.

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

Sidebar

Ask A Question

Stats

  • Questions 374k
  • Answers 374k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Make the instance a global: $newobj = new classname1; class… May 14, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer I finally was able to get the right content-type in… May 14, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer How are the lines read? If you're using StreamReader.ReadLine (or… May 14, 2026 at 8:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.