Question
Python : Given two non-empty arrays of integers, write a function that determines whatever the second array is a subsequence of the first one. A
Python :
Given two non-empty arrays of integers, write a function that determines whatever the second array is a subsequence of the first one. A subsequence of an array is a set of numbers that aren`t necessarily adjacent in the array, but that are in the same order as they appear in the array. For example: the numbers [1,3,4] form a subsequence of the array [1, 2, 3, 4], and so do the numbers [2, 4]. Note that a single number is an array and the array itself are both valid subsequences of the array. Sample Input: Array to check : 5,1,22,25,6,-1,8,10 Sequence to check if is subsequence of the array : 1,6,-1,10 Sample output: True
b) Modify the method so that it accepts one modifier that changes the logic (adjacent). If this modifier is given by the user a subsequence is valid only when its numbers are contained in the array, in the same order and are adjacent. Sample Input: Array to check : 5,1,22,25,6,-1,8,10 Sequence to check if is subsequence of the array : 1,6,-1,10,adjacent Sample output: False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started