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
3
votes
3 answers

What uses are there for String#subSequence()

So I read this answer and this answer on the differences between subSequence() and subString() and I understand that the only difference between the two is the return type. In fact, subSequence() calls subString() under the hood. In addition, this…
Very Objective
  • 601
  • 7
  • 16
3
votes
2 answers

Python: Identifying and deleting duplicate sequences in list

I'm looking for the best way to find duplicate sequences in a list. A sequence is defined as at least two neighbouring values. Example: In the following list, the repeating sequence should be identified and deleted. a = [45874, 35195, # <- …
Vingtoft
  • 13,368
  • 23
  • 86
  • 135
3
votes
0 answers

Count of distinct substrings in string inside range

Having string S of length n, finding the count of distinct substrings can be done in linear time using LCP array. Instead of asking for unique substrings count in whole string S, query q containing indexing (i,j) where 0 <= i <= j < n is asking for…
Akhilesh
  • 51
  • 7
3
votes
1 answer

R - how to find longest duplicate sequences and their frequencies

I have some data that looks like this: 29 32 33 46 47 48 29 34 35 39 40 43 29 35 36 38 41 43 30 31 32 34 36 49 30 32 35 40 43 44 39 40 43 46 47 50 7 8 9 39 40 43 1 7 8 12 40 43 There is actually a lot…
Nena
  • 681
  • 1
  • 10
  • 27
3
votes
3 answers

How to check if an ordered non-consecutive subsequence is in array? Python

I'd be surprised if this hasn't been asked yet. Let's say I have an array [5,6,7,29,34] and I want to check if the sequence 5,6,7 appears in it (which it does). Order does matter. How would I do this?
Graviton
  • 371
  • 1
  • 4
  • 14
3
votes
2 answers

Reorder a collection of elements in minimum number of steps in C#

I have a list of elements (namely PowerPoint slides) which I need to reorder in the minimal possible steps. Each slide has an integer unique key (namely SlideID), and I can produce the required order of keys really fast, but actually moving a slide…
vinczemarton
  • 7,756
  • 6
  • 54
  • 86
3
votes
5 answers

Find longest subsequence s of String in a dictionary

Find the longest subsequence s of a String such as "abccdde" and given a dictionary {"ab","add","aced"} . the result of above example is "add" I was asked in an interview, I gave an answer using trie tree and worst case is O(n*m) ,and n is length of…
Trumen
  • 31
  • 1
  • 4
3
votes
1 answer

Return all subsequences of an array-like with only consecutive values in Java

The problem I am trying to solve in Java requires dividing an input array into all allowable subsequences, where an allowable subsequence contains only consecutive values. For example, I would like {A,E,D} to return…
user3692741
3
votes
3 answers

Merge sequences of unique elements

I'm trying to merge a number of sequences, as in the following example: x = ['one', 'two', 'four'] y = ['two', 'three', 'five'] z = ['one', 'three', 'four'] merged = ['one', 'two', 'three', 'four', 'five'] The given sequences are all subsequences…
lenz
  • 5,658
  • 5
  • 24
  • 44
3
votes
1 answer

Ruby - Finding the Maximum Difference among subarrays

I came across a question from a coding challenge site that deals with subsequences. Given an array of integer elements, a subsequence of this array is a set of consecutive elements from the array (i.e: given the array v: [7, 8, -3, 5, -1], a…
Johnson
  • 1,679
  • 1
  • 14
  • 21
3
votes
2 answers

number of distinct subsequence

There is a leetcode problem: distinct subsequences. Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be…
3
votes
3 answers

When to use String.subSequence method over String.subString?

I know subSequence returns a charSequence which is a read-only. Also, String class implements CharSequence. subString returns a String. But, amongst subsequence and substring, when and which one to prefer
user3758749
  • 117
  • 1
  • 2
  • 6
3
votes
2 answers

Subsequence with a limit

This is my problem: Write a procedure distance(List, Nemptylist, SubList)/3 that checks if Sublist is a sublist of List with a distance of not more than N between items constraint (N is implemented as Nemptylist – a list of N anonymous…
kitsuneFox
  • 1,243
  • 3
  • 18
  • 31
3
votes
5 answers

Length of the longest sorted subsequence

My unsorted array is string[] a = new string[] { "10", "22", "9", "33", "21", "50", "41", "60", "80" }; In this array, 10,22,33,50,60,80 are in ascending order, so the output must be 6. In general, I want the longest possible length of an ascending…
Prashant16
  • 1,514
  • 3
  • 18
  • 39
2
votes
1 answer

Reverse LCS (longest common subsequence) algorithm: Minimal sequence containing given set of subsequences / shortest common supersequence

I'm trying to figure out how to compute the shortest sequence containing a given set of subsequences. For example, given: abcd bcdgh cdef The answer should be abcdefgh I was thinking about first computing the longest common subsequences of all…
Martin
  • 21
  • 1
1 2
3
20 21