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

printing all subsequences of an array using recursion in JAVA

The following code for above requirement. However I am not getting proper output. There is problem with input list that I am passing in recursion import java.util.ArrayList; import java.util.Collections; public class abc { public static…
0
votes
1 answer

Print all the subsequences of a string using recursion

I have tried a approach of print all the subsequences of a stirng using recursion but not able to implement this how can i print all the subsequences of a string in lexicographical order. INPUT:- abc OUTPUT: a b c ab ac bc abc I have tried this…
0
votes
0 answers

Longest increasing subsequence with minimum sum

I know there is a longest increasing subsequence algorithm that runs in O(nlogn) (https://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/), but what if there are multiple increasing subsequences of the same length…
0
votes
1 answer

Can't understand how to store values for each step

I am a beginner, trying to learn recursion and solve some problems (trying the subsequences problem). But before I could even attempt to get the recursion logic right, I am getting stumped while trying to store the values returned. Here is what I…
ArNY
  • 65
  • 1
  • 9
0
votes
1 answer

I need first subsequence with sum equal to k but instead i'm getting all subsequences in this code. How to solve this?

I'm returning true after a copy still i'm getting all sequences. def subset(nums,tot): res=[] def sub_seq(curr,i,s): if i==len(nums): if s==tot: res.append(curr.copy()) return True# Even…
0
votes
1 answer

How to modify a longest common subsequence algorithm to a longest common contiguous subsequence algorithm?

I'm wondering how to change the class I have so that it can produce the longest contiguous common subsequence between two strings. This code right now is setup so that I can get the length of the longest common subsequence of the two strings. I want…
Jake_3
  • 13
  • 1
0
votes
3 answers

Subsequence words

Suppose this is my .txt file ABCDBCD and I want to use .substring to get this: ABC BCD CDB DBC BCD How can I achieve this? I also need to stop the program if a line is shorter than 3 characters. static void lesFil(String fil, subsekvens…
0
votes
0 answers

Print subsequence which have sum 0 in Python list

I have a Numpy array (arr) and want to print all subsequences such that sum of values in the subsequence equals to zero. I have a code but in this I get subArrays. def findSubArrays(arr,n): hashMap = {} out = [] sum1 = 0 for i…
0
votes
1 answer

Time complexity of recursive Longest Common Subsequence which uses a map

I was reading 'Algorithms Unlocked' by Thomas H Corman and came across an approach to finding the Longest Common Subsequence which ran in O(n * m). This approach can be seen in this article too:…
60q
  • 35
  • 5
0
votes
1 answer

How to find longest subsequence based on conditions in Impala SQL

I have a SQL table on Impala that contains ID, dt (monthly basis with no skipped month), and status of each person ID. I want to check how long that each ID is in each status (my expected answer is shown on expected column) I tried to solve this…
0
votes
1 answer

Find a subset of maximum size n with XOR k

I have an array of size a = 10⁵ with numbers with sizes of at least 16 bytes. Now i have to find a subsequence with the xor value equal to k. The maximum length of this subsequence is n. (1 <= n <= 20) I tried BruteForce but even with many…
RD4
  • 135
  • 1
  • 12
0
votes
2 answers

How can I find the longest contiguous subsequence in a rising sequence in Python?

I need to find the longest contiguous subsequence in a rising sequence in Python. For example if I have A = [1, 2, 3, 5, 8, 9, 11, 13, 17, 18, 19, 20, 21, 25, 27, 28, 29, 30] The answer would be [17, 18, 19, 20, 21] because it's the longest…
swapman
  • 11
  • 2
0
votes
1 answer

Python count a subsequence in a string

My exercise consists in counting a subsequence in a binary string, but I can't use the count method because, for example, if I have the subsequence '00' in the string '10010000', the count method will return '3' but the correct answer is '4'. I…
0
votes
1 answer

Why is an ancestral array needed when recovering longest increasing subsequence?

I looked at the following website describing the longest increasing subsequnce algorithm: https://www.fyears.org/2016/12/LIS.html In the section "how to reconstruct the subsequence?", it says that "We should pay attention that the dp in the end is…
cat_20
  • 3
  • 1
0
votes
1 answer

Memoization of distinct subsequences problem, can anyone please memoize(cache) the following code?

def numDistinct(self, s: str, t: str) -> int: n = len(s) m = len(t) if n=n: return if length>m: …