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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:28:15+00:00 2026-05-11T13:28:15+00:00

What is an elegant algorithm to mix the elements in two arrays (of potentially

  • 0

What is an elegant algorithm to mix the elements in two arrays (of potentially differing sizes) so that the items are drawn in an alternating fashion from each array, with the leftovers added to the end?

E.g.

Array 1 – A, B, C, D, E, F, G

Array 2 – 1, 2, 3, 4

Mixed array – A, 1, B, 2, C, 3, D, 4, E, F, G

I would prefer the solution in C#, but I should be able to read and transpose solutions in any language (or even some form of pseudo code).

Don’t worry about null checking or any other edge cases, I’ll handle those.

  • 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. 2026-05-11T13:28:15+00:00Added an answer on May 11, 2026 at 1:28 pm

    You mean something along the lines of this?

    // naive/boring approach int i = 0; int m = 0; while (i < a1.size() || i < a2.size()) {     if (i < a1.size())         mixed[m++] = a1[i];     if (i < a2.size())         mixed[m++] = a2[i];     i++; } 

    If you use this, you’ll probably want to store the array lengths in variables so you don’t have to keep calling a size() method (or whatever it is in whatever language you use).

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

Sidebar

Related Questions

I'm writing an algorithm that iterates over a list of points, calculates the distance
What's the best algorithm to find the smallest non zero positive value from a
What is an elegant way to remove an object from an array of objects
What is the most elegant way to achieve something like that with divs for
What is an elegant way to sort objects in PHP? I would love to
Is there an elegant way to have performant, natural sorting in a MySQL database?
What is the most elegant way to solve this: open a file for reading,
Would there a more elegant way of writing the following syntax? Thread t0 =
Is there some elegant way to add an empty option to a DropDownList bound
Is there an elegant way to specialize a template based on one of its

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.