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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:23:37+00:00 2026-06-14T10:23:37+00:00

Given a non-empty array of items. You have to move all the items from

  • 0

Given a non-empty array of items. You have to move all the items from the right side to odd positions (zero-based), and from the left side — to even positions, as follows:

raw data: 0 2 4 6 8 10 12 14 1 3 5 7 9 11 13

result: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

What in-place algorithm exists for this with O(n) time complexity? What is its implementation?

The inverse problem is solved here (this algorithm can be essentially inverted, but it will look ugly).

  • 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-06-14T10:23:38+00:00Added an answer on June 14, 2026 at 10:23 am

    Here is only the algorithm itself. For details, explanations, and alternative approaches see answer for the inverse problem.

    1. Initialize pointer to the pool of right-side elements to N/2.
    2. Get largest sub-array having size 3k+1
    3. Join (3k+1)/2 elements from the array’s beginning and (3k+1)/2 elements from the pool of right-side elements by exchanging appropriate sub-arrays. Update pool pointer.
    4. Apply cycle leader algorithm to the parts of this sub-array, starting from positions 1, 3, 9, … 3k-1: move element to its proper position in sub-array (elements from the left of sub-array to even positions, from the right – to odd positions), the replaced element should be also moved to its proper position, etc. until this procedure comes back to the starting position.
    5. Process the remaining parts of the array recursively, using steps 2 .. 4.

    This problem is simpler than the inverse problem, referred in OP, because here we have to reorder sub-arrays starting from the larger ones, in the same order as doing cycle leader algorithm (the inverse problem has to do it separately and in reverse order, starting from the smaller ones to obtain O(N) complexity).

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

Sidebar

Related Questions

Find the first covering prefix of a given array. A non-empty zero-indexed array A
I have the below Problem Statement PS: Given a string str and a Non-Empty
Given that I have m non-empty distinct sets (labeled Z[ 1 ], Z[ 2
Below is the Problem Statement: PS: Given a string and a non-empty substring sub,
Given I have an array: $array = array( 'a' => array( 'b' => array(
I want to solve the following optimization problem: Non-Latex: Given x and mu, find
Given: I added a non-nullable foreign key to a table. I settled on a
Given a crash report (non-symbolicated) on iOS, is there a way to determine which
Given an arbitrary file descriptor, can I make it blocking if it is non-blocking?
When a non built-in module is imported, the interpreter searches in the locations given

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.