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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:07:15+00:00 2026-05-15T15:07:15+00:00

Given 2 arrays Array1 = {a,b,c…n} and Array2 = {10,20,15….x} how can I generate

  • 0

Given 2 arrays Array1 = {a,b,c...n} and Array2 = {10,20,15....x} how can I generate all possible combination as Strings a(i) b(j) c(k) n(p)
where

1 <= i <= 10,  1 <= j <= 20 , 1 <= k <= 15,  .... 1 <= p <= x

Such as:

a1 b1 c1 .... n1  
a1 b1 c1..... n2  
......  
......  
a10 b20 c15 nx (last combination)

So in all total number of combination = product of elements of array2 =
(10 X 20 X 15 X ..X x)

Similar to a Cartesian product, in which the second array defines the upper limit for each element in first array.

Example with fixed numbers,

    Array x =  [a,b,c]
    Array y =  [3,2,4] 

So we will have 3*2*4 = 24 combinations. Results should be:

    a1 b1 c1  
    a1 b1 c2  
    a1 b1 c3  
    a1 b1 c4  

    a1 b2 c1  
    a1 b2 c2  
    a1 b2 c3  
    a1 b2 c4


    a2 b1 c1  
    a2 b1 c2  
    a2 b1 c3  
    a2 b1 c4  

    a2 b2 c1  
    a2 b2 c2  
    a2 b2 c3  
    a2 b2 c4


    a3 b1 c1  
    a3 b1 c2  
    a3 b1 c3  
    a3 b1 c4  

    a3 b2 c1  
    a3 b2 c2  
    a3 b2 c3  
    a3 b2 c4 (last)
  • 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-15T15:07:16+00:00Added an answer on May 15, 2026 at 3:07 pm
    using System;
    using System.Text;
    
    public static string[] GenerateCombinations(string[] Array1, int[] Array2)
    {
        if(Array1 == null) throw new ArgumentNullException("Array1");
        if(Array2 == null) throw new ArgumentNullException("Array2");
        if(Array1.Length != Array2.Length)
            throw new ArgumentException("Must be the same size as Array1.", "Array2");
    
        if(Array1.Length == 0)
            return new string[0];
    
        int outputSize = 1;
        var current = new int[Array1.Length];
        for(int i = 0; i < current.Length; ++i)
        {
            if(Array2[i] < 1)
                throw new ArgumentException("Contains invalid values.", "Array2");
            if(Array1[i] == null)
                throw new ArgumentException("Contains null values.", "Array1");
            outputSize *= Array2[i];
            current[i] = 1;
        }
    
        var result = new string[outputSize];
        for(int i = 0; i < outputSize; ++i)
        {
            var sb = new StringBuilder();
            for(int j = 0; j < current.Length; ++j)
            {
                sb.Append(Array1[j]);
                sb.Append(current[j].ToString());
                if(j != current.Length - 1)
                    sb.Append(' ');
            }
            result[i] = sb.ToString();
            int incrementIndex = current.Length - 1;
            while(incrementIndex >= 0 && current[incrementIndex] == Array2[incrementIndex])
            {
                    current[incrementIndex] = 1;
                    --incrementIndex;
            }
            if(incrementIndex >= 0)
                ++current[incrementIndex];
        }
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • 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 This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 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

Related Questions

Given an array of strings, array1 = [abcdwillbegoneabcccc,cdefwilbegokkkabcdc] and another array of strings which
Given an array: array1 = [1 2 3]; I have to reverse it like
Saw this question recently: Given 2 arrays, the 2nd array containing some of the
i have seen a few days ago such problem there is given two array
If I have two associative arrays, what would be the most efficient way of
Summary: Given an array {a, b, ..., w, x, ..., z} insert several elements
I need to convert a navigable map to a 2D String array. Below given
Given: var a1 = [{name:'Scott'}, {name:'John'}, {name:'Albert'}]; var sortOrder = ['John', 'Scott', 'Albert']; How
The purpose of this question is to find the best way to print data
I'd like to calculate the square and square-root of a vector of doubles. For

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.