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

LeetCode longest Increasing Subsequence

I am working on the following leetcode problem: Given an integer array nums, return the length of the longest strictly increasing subsequence. The solution given is O(N^2) time but I have the following solution that does not work in it's current…
user10100511
0
votes
1 answer

Finding position of subsequence in a sequence

l1 = "GATATATGCATATACTT" l2 = "ATAT" for i in range(len(l1)): if l1[i] == "A" and l1[i+1] == "T" and l1[i+2] == "A" and l1[i+3] == "T": print (i+1) L1 is the main seq L2 is the sub sequence that I am trying to find in L1. The above code…
0
votes
0 answers

What could be wrong with my code so that instead of printing all the subsequences of a string it is printing an empty subsequence?

Hi I have tried to print all subsequences of a string but it is not giving the output please help me if there is an error in my code I couldn't figure what's wrong with my code as I am still learning please help me out Here I am passing two inputs…
0
votes
1 answer

Print all Palindromic Subsequences in a given string (not distinct)

There are many problems of this kind on GFG like Count All Palindromic Subsequence in a given String. But I have not found this question anywhere: Print all Palindromic Subsequences in a given string (not distinct). I looked at this article on GFG…
Ritika Gupta
  • 493
  • 4
  • 14
0
votes
1 answer

Comparing values in two different dictionaries

Given two dictionaries a={'aabb': ['aabb'], 'abcd': ['abcd', 'abce', 'abcf'], 'abbc': ['abbc']} b={'aabb': 1, 'abcd': 2, 'abbc': 1} Get the all values from a where thr key has a max value in b in example : In b 'abcd' has a max value so we…
deepakkadali
  • 31
  • 1
  • 1
  • 4
0
votes
1 answer

Time out error (array is subsequence of another array)

I wrote this code in my computer's IDE and passed all test cases I could think of. However, after testing it out on AlgoExpert and LeetCode, I'm getting a Time Out error. I've wracked my brain trying to come up any test cases I could've missed, but…
Giao Tran
  • 135
  • 1
  • 2
  • 10
0
votes
5 answers

Simple method to find 0,0,1 in that order, within a given List

I am trying to write a simple function to find if 0,0,1 occurs in a list, in that order. It should return True or False. The list can contain any number of numbers. For the function ZeroZeroOne examples would be as follows: >> ZeroZeroOne( [0,0,1]…
whytheq
  • 34,466
  • 65
  • 172
  • 267
0
votes
1 answer

Run all instances of function one at a time, prevent function from interrupting itself

Currently the JavaScript runs perfectly fine on one click. However, when I click the "Test Test" button while the function is already running, it will seemingly interrupt itself. I want the second click to queue itself up and wait until the "Thank…
Justin
  • 15
  • 3
0
votes
1 answer

STD function to return the first iterator where a subsequence begins

Is there a way to return a distance between the first iterator of a sequence, which yields the start of a subsequence in case it is contained within the sequence? I know there is std::includes which returns true if a sequence is a subsequence of…
Sergey Kolesnik
  • 3,009
  • 1
  • 8
  • 28
0
votes
1 answer

Binary String Reduction

you are given a binary string (only 0's and 1's) s of length n. you want to convert s into an empty string by performing the following operation the least number of times. In one Operation, you can remove an alternating subsequence from s without…
0
votes
1 answer

How to find if given string is a subsequence of another given string recursively without imports?

Assignment: Write a recursive function named is_subsequence that takes two string parameters and returns True if the first string is a subsequence of the second string, but returns False otherwise. We say that string A is a subsequence of string B…
Loom
  • 21
  • 2
0
votes
0 answers

NIce Subsequence - A variant of Longest Increasing Subsequence

A subsequence X[1..k] is nice if X[i] > X[i - 2] for all i > 2. Compute a longest nice subsequence of an arbitrary array of integers A[1...n]. I have some confusions regarding this problem statement as no examples were provided. I took an example…
anony_std
  • 29
  • 6
0
votes
1 answer

Why my logic for Longest Common Subsequence for 3 sequences is not robust?

I have a question regarding this problem and my solution. Given three sequences a,b,c - I used the logic of finding the longest common sub-sequence value of each pair (a,b), (b,c) and (c,a). Then finding the minimum of the three. Which should give…
0
votes
1 answer

why am i getting slightly off outputs for this dp problem?

The Question: Given an array A of N distinct integers and an array B of integers(need not be distinct). Find the min no. of numbers that need to be added to B to make A a subsequence of it. My Strategy: Quite simple- find the longest common…
dagwood
  • 379
  • 1
  • 2
  • 13
0
votes
1 answer

Concurrent Modification Exception while adding elements to ArrayList recursively

Getting Concurrent Modification Exception while adding elements to ArrayList recursively. import java.util.*; public class Hello { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); …
Himanshu Sharma
  • 511
  • 5
  • 12