BackmediumArrays Paytm

Asteroid Sequence Validator Solution

Problem Statement

Given a list of asteroid sizes and a target sequence, determine if the target sequence appears in the same order and is consecutive within the asteroid list.

Example 1
Input
[543,214,87,654,321], [214, 87, 654]
Output
false

Explanation: Step-by-step: Given the asteroid list [543,214,87,654,321] and the target sequence [214, 87, 654], we check if the target sequence appears consecutively in the asteroid list. Since 543 is not part of the target sequence, we return false.

Example 2
Input
[11,23,35,47,59], [23, 47]
Output
false

Explanation: Step-by-step: Given the asteroid list [11,23,35,47,59] and the target sequence [23, 47], we check if the target sequence appears consecutively in the asteroid list. Since 11 is not part of the target sequence, we return false.

Constraints

  • 1 <= asteroidSizes.length <= 10^5
  • 1 <= targetSequence.length <= 100
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free