[Python] Collision of array elements

Discussão em 'Python' iniciado por Stack, Janeiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    Is it feasible to design an algorithm like this? Specifically, is it possible to write a Python code for the following logic?

    You have an array of numbers (e.g., 1533 consecutive numbers). It doesn't have to be from 1 to 1533 — it can be a range like 10,000 to 11,532.

    X starts from the beginning of the array and moves forward, adding the first value to its own array. Y starts from the end of the array and moves backward, adding the last value to its own array. Each time X takes a value, it checks if that value already exists in Y's array. Each time Y takes a value, it checks if that value already exists in X's array.

    The goal is for X and Y to meet somewhere or in the middle of the array.

    I saw Jump Game II so I thought maybe to code this... But I have a problem with the jumps design...I mean sometimes they collide sometimes not

    The challenge is to design progressive jumps for both X and Y, meaning that the steps they take increase gradually, but neither X nor Y should reach the end of the array before they collide.

    You cannot use linear steps like +1, +1, +1 or -1, -1, -1. Instead, the jumps must increase progressively (e.g., +1, +2, +3, +5...).

    Continue reading...

Compartilhe esta Página