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
2 answers

How can I find the number of non-decreasing subsequences in an array?

Given an array of positive integers, I want to find out the number of non-decreasing sub-sequences in the array. For example if the array is {6,7,8,4,5,6}, non decreasing sub-sequences would be…
Pallab Ganguly
  • 3,023
  • 2
  • 10
  • 10
0
votes
1 answer

Does a subsequence need to be continuous

I am new to Dynamic Programming and was reading on the Longest Increasing Subsequence(LIS) problem. The solution stated that the sequence need not be continuous as in the original array. Elements can be skipped in between; but I was under another…
0
votes
1 answer

Find all contiguous subsequences of an array of sum k

Example: The array is as follows: -4 -10 -15 - 20 100 -67 47 20 and k = 51 Expected output: -4 -10 -15 - 20 100 -4 -10 -15 - 20 100 -67 47 20 Tried the brute force solution with O(n^2). Can anyone please suggest a better solution to this?
Pooja N Babu
  • 347
  • 3
  • 5
  • 15
0
votes
1 answer

Counting contigious subsequences in an array with given pair of indices

Given an array of length n, for every index i have a integer xi (xi<=i). I need to count all continous subsequences that include these two indices also there should be no repetition for eg. I have counted the subsequence [1,4] for say (i=4 &&…
oflocon
  • 11
  • 4
0
votes
1 answer

Maximum contigous subsequence sum of x elements

So I came up with a question that I've looked and searched but with no answer found... What's the best (and by saying the best, I mean the fastest) way to get the maximum contigous subsequence sum of x elements? Imagine that I've: A[] = {2, 4, 1,…
0
votes
1 answer

collect sequences in list in python

Assuming that I have a sorted list: a=[1,2,3,4,5,6,10,11,12,13,14,15,16,20,23,25,26,27] How can I get subsequence in a like: [(1,2,3,4,5,6),(10,11,12,13,14,15,16),20,23,(25,26,27)]
Tardis Xu
  • 1,161
  • 2
  • 7
  • 9
0
votes
1 answer

Code verifcation and optimization - Two String common substring

I was solving Two String problem. I have written below code. It passed 4 test cases but for two test cases it showed timeout. Kindly let me know how can I optimize it to avoid timeouts? Also any links which explains and shows examples of such…
nanosoft
  • 2,913
  • 4
  • 41
  • 61
0
votes
1 answer

Find two disjoint susequences with minimum difference( > n)

You are given an array of positive numbers and you need to find two disjoint sub sequences with minimum difference less than or equal to n. These sub sequences may or may not be contiguous For Example if array = [10,12,101,105,1000] and n = 10 Ans…
sky_coder123
  • 2,161
  • 3
  • 14
  • 15
0
votes
4 answers

Can someone please explain this algorithm in C++?

Quadratic Maximum contiguous subsequence sum algorithm int maxSubSum2( const vector & a) { int maxSum = 0; for (int i = 0; i< a.size(); ++i) { int thisSum = 0; for (int j = i; j < a.size(); ++j) { thisSum += a[j]; …
0
votes
2 answers

Parent string of two given strings

Given 2 strings, we have to find a string smallest in length such that the given strings are subsequences to the string. In other words, we need to find a string such that deleting some characters result in the given strings. was thinking of brute…
rjalfa
  • 729
  • 1
  • 8
  • 14
0
votes
1 answer

maximum subsequence product special cases

I'm attempting to write a maximum subsequence product program that is based off of the recursive solution to the maximum subsequence sum program (that is, it will follow the same format). It works so far on all cases except those where the result…
user1837165
  • 41
  • 1
  • 6
0
votes
0 answers

Unable to take a subsequence or substring of a large String

I have been trying to parse a JSON file. It was somewhat out of structure, so , to get in a structure I am using a subsequence of that file (so that it gets in a structure). But when I am using subsequence or substring, then it is just omitting the…
Devyani
  • 43
  • 9
0
votes
3 answers

Find minimum element of a subsequence

Given a sequence S of n integer elements, I need a function min(i,j) that finds the minimum element of the sequence between index i and index j (both inclusive) such that: Initialization takes O(n); Memory space O(n); min(i,j) takes…
Palak Jain
  • 143
  • 1
  • 3
  • 14
0
votes
1 answer

Why does the base case in recursive solution to find the maximum subsequence in a given sequence return 0 if the number is negative?

Below is a sample code in C++ written using recursion to solve the maximum subsequence problem - not exactly the subsequence, but the sum of the maximum subsequence. int maxSumRec( const vector & a, int left, int right ) { if( left == right )…
Guruprasad
  • 1,447
  • 4
  • 16
  • 34
0
votes
1 answer

find longest subsequence with non-negative sum

Let's say we have an array of n real numbers. We want to find the longest contiguous subsequence in the array that it's sum is greater or equal zero. It has to be done in linear time. We actually have no idea how to start answering this. Thanks in…
user76508
  • 267
  • 2
  • 8