Questions tagged [subsequence]

A subsequence is a sequence obtained by deleting some elements and retaining the relative order of the remaining elements. It is a generalization of substring which contains only consecutive elements of the original sequence.

A subsequence is a sequence obtained by deleting some elements and retaining the relative order of the remaining elements. It is a generalization of substring which contains only originally consecutive elements.

303 questions
0
votes
1 answer

What is difference between printing all subsets and printing all sub sequences of a string or integer array using recursion

Does the recursive code for printing all the subsets of a string and printing all the sub-sequences of a string varies? As we know that sub sequences of a string are part of the subsets of a string for example: string str="abc"; sub sequences of str…
Hemant Rai
  • 31
  • 6
0
votes
2 answers

Longest subsequence whose sum is divisible by k

I am practicing some Dynamic Programming problems and encounter this problem Given an array of n(1<=n<=1000) integers and a positive integer k(k<=1000). Find the longest subsequence whose sum is divisible by k. For example, a =…
0
votes
1 answer

How to make this Longest Increasing Subsequence program return this subsequence

I have this code for Longest Increasing Subsequence. Right now it returns length of the longest increasing subsequence, but I don't know how to make it return this exact subsequence. For ex. in this case it should return [3,6,7,8,9]. Any ideas? I…
lolos
  • 37
  • 1
  • 5
0
votes
2 answers

Fast way to check consecutive subsequences for total

I have a list (up to 10,000 long) of numbers 0, 1, or 2. I need to see how many consecutive subsequences have a total which is NOT 1. My current method is to for each list do: cons = 0 for i in range(seqlen+1): for j in range(i+1, seqlen+1): …
Theo
  • 613
  • 4
  • 22
0
votes
1 answer

Largest consecutive subsequence, return subsequence and length

I have a function that returns the length of the subsequence but I also need to return the subsequence itself but i'm having trouble getting it to work. I have tried the following code but the subsequence only returns correctly if it's the first…
duronic
  • 167
  • 1
  • 3
  • 11
0
votes
2 answers

Maximum Sum Increasing Subsequence

So I made a simple python code using Dynamic programming to solve the problem of Maximum Increasing Subsequence. The Question is as follows: Given an array arr of N positive integers. Find the sum of maximum sum increasing subsequence of the given…
0
votes
2 answers

Find sub sequence of array that have negative multiplication

I'm trying to build an algorithm that given me count of subsequence that have a negative product of their elements. For example: Answer for [-1, 2, -3] is 4. ([-1] [-3] [-1, 2] and [2, -3])
Sam
  • 21
  • 3
0
votes
2 answers

finding all possible subsequences in a given string

I have written this piece of code and it prints all substrings of a given string but I want it to print all the possible subsequences. from itertools import combinations_with_replacement s = 'MISSISSIPPI' lst = [] for i,j in…
challenger
  • 23
  • 1
  • 4
0
votes
1 answer

In Excel, find longest subsequence matching some criteria

I have a sequence of numbers in an Excel worksheet, and I'd like to find the longest subsequence that matches some criteria. For example, say I have the following: and I'd like to know where the longest subsequence with every value less than 10…
blm
  • 2,379
  • 2
  • 20
  • 24
0
votes
4 answers

bash subsequence matching speed-up

I am wondering if there is an easy way to check if a string is a subsequence of another string in bash, actually a subsequence with an extra rule. I will explain. Some subsequences of "apple" are "aple", "al", "pp" and "ale". The subsequences with…
fangio
  • 1,746
  • 5
  • 28
  • 52
0
votes
0 answers

Given an array of positive numbers, find the maximum subsequence sum <= given sum, such that no two elements are adjacent to each other

This is my code It passes for few cases but not for all, for eg. number of elements n = 6 elements a[n] = {5,5,10,100,10,5} and sum = 25 the output is 15, but output should be 25 (5 + 10 + 10) click here to see its working in…
Mohit
  • 590
  • 5
  • 13
0
votes
1 answer

Is there a way to memorize a subSequence into a variable?

I'm making a program that should ignore ( and ) in words (without the use of RegExp), and through the method I created, I want my variable x to memorize the new String. How can I access subSequence in such way or circumvent my issue through another…
soulblast
  • 3
  • 1
0
votes
0 answers

Longest increasing subsequence after rearranging k subarrays

I require a way to find an increasing subsequence of a given array which consists of distinct natural numbers from 1 to n in some random manner, after rearranging exactly k subarrays(continuous elements). But elements within the subarray cannot be…
rocket
  • 1
  • 1
0
votes
3 answers

Printing longest subsequence of letters using Python

Write a block of code to print the longest subsequence of letters out of an input string. - First, ask user to input any string. - You code should print the longest sub-string of the input string, which contains only letters of the English…
0
votes
0 answers

Find sum of gcd of all subsequence of size K from 1 to n (in O(nlogn))

Suppose a[]={1,2,3,4,5} and K=3 Sum of gcd of all subsequence of size k = gcd(1,2,3)+gcd(1,2,4)+gcd(1,2,5)+gcd(1,3,4)+gcd(1,3,5)+gcd(1,4,5)+gcd(2,3,4)+gcd(2,3,5)+gcd(2,4,5)+gcd(3,4,5). How can we find this for different values of…