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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:52:38+00:00 2026-05-13T23:52:38+00:00

Assume that we have multiple arrays of integers. You can consider each array as

  • 0

Assume that we have multiple arrays of integers. You can consider each array as a level. We try to find a sequence of elements, exactly one element from each array, and proceed to the next array with the same predicate. For example, we have v1, v2, v3 as the arrays:

v1  | v2  | v3
-----------------
1   | 4   | 16
2   | 5   | 81
3   | 16  | 100
4   | 64  | 121

I could say that the predicate is: next_element == previous_element^2
A valid sequence from the above example is: 2 -> 4 -> 16
Actually, in this example there isn’t another valid sequence.
I could write three loops to brute-force the mentioned example, but what if the number of arrays is variable, but with know order of course, how would you solve this problem?

Hints, or references to design patters are very appreciated. I shall do it in C++, but I just need the idea.

Thanks,

  • 1 1 Answer
  • 1 View
  • 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-13T23:52:39+00:00Added an answer on May 13, 2026 at 11:52 pm

    If you order your arrays beforehand, the search can be done much faster. You could start on your smaller array, then binary-search for expected numbers on each of them. This would be O(nklogM), n being the size of the smallest array, k being the numbers of arrays, M being the size of larger array

    This could be done even faster if you use Hashmaps instead of arrays. This would let you search in O(n*k).

    If using reverse functions (to search in earlier arrays) is not an option, then you should start on first array, and n = size of first array.

    For simplicity, I’ll start from first array

    //note the 1-based arrays
    for (i : 1 until allArrays[1].size()) {
      baseNumber = allArrays[1][i];
      for (j: 2 until allArrays.size()) {
        expectedNumber = function(baseNumber);
        if (!find(expectedNumber, allArrays[j]))
            break;
        baseNumber = expectedNumber;
      }
    }
    

    You can probably do some null checks and add some booleans in there to know if the sequence exist or not

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

Sidebar

Related Questions

Assume that I have two arrays as follow: $array1 = array(1, 3, 5); $array2
Assume that we have an array of integers (3x3) depicted as follows: +-+-+-+ |
Assume that we have 3 different activities. Each activity has its own XML file
Assume that I have this piece of code: @interface Foo : NSObject { Bar
Assume that I have the ItemSource bound and i am getting the data. Now
Assume that we have the following code: class Program { static volatile bool flag1;
Assume that I have three class; UserAccount, UserGroup and Role. UserGroup and Role are
Assume that I have a text file separated by colons. I understand how to
Let's assume that we have a vector like x = -1:0.05:1; ids = randperm(length(x));
(Let's assume that I have good reasons not to remove my NSAssert() checks 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.