Note that there are some explanatory texts on larger screens.

plurals
  1. POMaximum Possible Ways of Merging Two Arrays
    primarykey
    data
    text
    <p>Suppose I have two arrays of size <code>m</code> and <code>n</code>:</p> <p><code>a[1] a[2] a[3] ..... a[m]</code></p> <p>and</p> <p><code>b[1] b[2] b[3] ..... b[n]</code></p> <p>I want to form a new array merging these two arrays such that in the new array of <code>m + n</code> elements, <code>a[i]</code> is always placed befor <code>a[i + 1]</code> and <code>b[i]</code> is always placed before <code>b[i + 1]</code>. For example, <code>a[1] a[2] b[1] b[2]... b[n] a[m]</code> will be a valid array but <code>a[2] a[1] b[1] b[2] ... b[n] a[m]</code> won't. Given <code>m</code> and <code>n</code>, how many such combinations will be possible when repeating is allowed?</p> <p>I have the intuition to solve the problem:</p> <p><code>- b[1] - b[2] - b[3] - ..... - b[n]</code></p> <p>I can place <code>a[1]</code> in any of the <code>n - 1</code> places within the array <code>b</code>, and considering the front and the last place, I have <code>n + 1</code> total ways of placing <code>a[1]</code>. If I place <code>a[1]</code> in the first place (just before <code>b[1]</code>), I can now place <code>a[2]</code> in <code>n + 1</code> places. But if I place <code>a[1]</code> just after <code>b[1]</code>, I would have <code>n</code> ways to place <code>a[2]</code>. I can apply this approach recursively for all <code>a[i]</code> where <code>1 &lt;=i &lt;= n</code>. But I can't find any mathematical formula to express the solution, besides I can't understand how to approach when repeating is allowed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload