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

Number of subsequences of size k and sum s

Consider an array A with length n. Let k be the length of subsequences to be generated. What I want to do is to get the number of subsequences with length k and sum s. Example: A = [1,1,2,2,3] s = 4 k = 2 So output would be 3 -> [{1,3}, {1,3},…
user9469335
  • 192
  • 1
  • 10
0
votes
3 answers

Finding maximum possible count of elements in list whom all sharing at least one same digit

There is a problem where array containing numbers is given, the statement is to find the maximum length of a sub-sequence formed from the given array such that all the elements in that sub-sequence share at least one common digit. Now whats the…
0
votes
0 answers

What are the differences in time and space complexity between these 2 algorithms that solve leetcode 873?

I have just solved https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/. The objective is to find the longest Fibonacci sub-sequence in an array of strictly increasing integers. I need some help figuring out the difference in time…
d_darric
  • 387
  • 2
  • 15
0
votes
2 answers

Non destructive subsequence-except in lisp

I know subseq in lisp return a subsequence through a range. Is there anything which will return the subsequence except that range and should be non-destructive? Any help is appreciated.
Anowarul Kabir
  • 47
  • 1
  • 1
  • 6
0
votes
1 answer

Subsetting a sequence excluding numbers < and > x from a vector

I am trying to create a new vector C by subsetting all the numbers from a vector A which are smaller than 25 and greater than 75. My problem is how and where to position the command subsetting the range I want. set.seed(135) A <- sample(1:100,1000,…
Anna
  • 1
  • 1
0
votes
2 answers

splitting a list into sorted sublists

I'm trying to split a list with ints into sublists with ascending values. as an example: [1;2;3;3;4] should go into [[1;2;3;3;4]] and a list [1;2;3;2;4;3;5] -> [[1;2;3],[2;4],[3;5]]. I was trying to do it through tail recursion but I can't figure…
user10767900
0
votes
0 answers

Querying for a subsequence using Django ArrayFields

I have an ArrayField that stores sequences of integers in it, for example: Sequences.objects.first().seq returns [5,4,4,3,2,2,1]. The sequences are always stored in decreasing order, and I want to filter Sequences to find a subsequence. However, I'm…
0
votes
4 answers

How to generate all subsequence of even length from an array?

I am dealing with a problem and that problem requires the answer to this as a subroutine. I know how to generate all subsequences from an array using bit manipulation but struggling to generate subsequences of even length. For the sake of example,…
0
votes
1 answer

Common Subsequence in Different Length Arrays

I've implemented a DP algorithm that finds the longest common subsequence in three arrays. The problem though, is that my algorithm doesn't work when the arrays are of different lengths, and I have no idea why. From what I can tell, my algorithm is…
0
votes
2 answers

Count integers up to n that contain the digits 2018 in order

Given an integer n between 0 and 10,0000,0000, count the number of integers smaller than n which contain the digits [2,0,1,8] in order. So e.g. the number 9,230,414,587 should be counted, because removing the digits [9,3,4,4,5,7] leaves us with…
ileadall42
  • 631
  • 2
  • 7
  • 19
0
votes
2 answers

recursive function - subsequence

I'm trying to get a recursive Function, which should compare two int arrays and say wether array2 is a subsequence of array1. My Problem is now that i dont know when to set the return value of an bool recursive function. I'm glad for every help. int…
Truut
  • 83
  • 1
  • 11
0
votes
0 answers

Last Common subsequence SQL

I'm looking to find the last Common Subsequence between two strings in sql. For instance, I have this two strings "A#CDE#FGH" and "FGH#IJK#CDE", in this case the last common subsequence is FGH (the last one in the first string). Does anyone know how…
jacen44
  • 168
  • 3
  • 18
0
votes
2 answers

Racket: sliding window over a vector

What are some good ways to perform a sliding window over a finite sequence in Racket, such as finding the highest sum of any sub-sequence of 4 numbers? (define example #(3 1 4 5 10 23 1 50 0 12 40 12 43 20))
Meow
  • 1,610
  • 1
  • 14
  • 18
0
votes
1 answer

Longest Increasing Subsequence Efficient Algorithm Implementation in Python

I am trying to write an efficient 0(nlogn) algorithm for longest increasing subseuqnce: def whereToInsert(a, k): l, r = 0, len(a)-1 while l<=r: m = l + (r-l)//2 if a[m]==k: return m elif a[m]>k: …
mourinho
  • 763
  • 6
  • 13
  • 24
0
votes
1 answer

What is the logic to use bitwise operation in generating subsequences?

I have an array, A=[1,2,3,4] (where n=4). I want to generate sub-sequences from this array. Number of subsequences is (2^n -1) Run from counter 0001 to 1111 for (int counter = 1; counter < 2^n; counter++) { for (int j = 0; j < n; j++) …
miltonbhowmick
  • 324
  • 1
  • 5
  • 17