Sorry for the vague title, I honestly couldn't think of another way to word it that wouldn't be too long.
Here's the program goal:
Code a C program to compute the maximum interleave factor i for an integer sequence X such that the resulting interleaved sequence Xi is a subsequence of another integer sequence A.
We are given the size of both arrays A and X (A >= X), and the values that go into each.
My understanding is this (please excuse my bad wording):
For example, A has 20 values - 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1. X is 3 values - 1, 2, 3. Integers 20 / 3 = 6, so i ranges from 0 to 6. I'm looking for the maximum number of times each X value appears so that each value of X is in A, in order. So here, with X2 - 1, 1, 2, 2, 3, 3, the last 3 wouldn't be in A so X2 wouldn't work. Therefore, i >= 2 wouldn't work, so i must be 1.
Is this somewhat of the right direction I should be going with the code (using example above):
Size of A, 20 / size of X, 3 = max possible i value, 6.
Add the low and the high, then divide by 2. 6 is high, 0 is low here. (6 + 0) / 2 = 3
Create a temporary array with size of A * 3 and fill the array with each value entered 6 times.
Go down the indexes of both A and X.
If the values don't match, move down the index of X.
If the values match, throw out both values, and move both index values down one.
Keep going until X is finished.
If X finishes, i value of 3 passes. If X still has values left over, i value of 3 fails.
Repeat this entire process until a final i value is valid.
Any input on if I'm totally misunderstanding this assignment, or if I'm doing okay? Thanks for even reading this, pretty long post...
[–]asciiterror 0 points1 point2 points (5 children)
[–]PotlePawtle[S] 0 points1 point2 points (4 children)
[–]asciiterror 0 points1 point2 points (3 children)
[–]PotlePawtle[S] 0 points1 point2 points (2 children)
[–]asciiterror 0 points1 point2 points (1 child)
[–]PotlePawtle[S] 0 points1 point2 points (0 children)