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 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 got these virtual classes from a library that implement an algorithm in the
I need to go through a set and remove elements that meet a predefined
I've found a solution that looks quite elegant but i don't understand its behavior.
I'm trying to develop an algorithm that can report the frequency and closeness in
What's the best algorithm to find the smallest non zero positive value from a
I have an algorithm that calculates the amount an object has rotated. It calculates
what is the most elegant and simple algorithm to map a sequential collection such
I'm writing an implementation of the XXTEA encryption algorithm that works on streams, ie,
I would like to get 2 random different elements from an std::vector. How can
Is there an elegant method to create a number that does not exist in

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.