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
-1
votes
1 answer

Dictionary value returning nil in Swift

In this code, I am trying to extract week days from a string. I created a dictionary named dayDictionary to access to week days faster dayDictionary is populated perfectly, but I can't access the element, it always returning nil dictionary accessing…
SHAH MD IMRAN HOSSAIN
  • 2,558
  • 2
  • 25
  • 44
-1
votes
1 answer

I am not getting desired output what is the problem in the code

Given a string. Find the longest palindrome subsequence. The string contains an only lowercase letter. Here, I am creating the array with the length of 26 and keeping track of all lowercase letters (i.e how many times they occur in the string).…
-1
votes
1 answer

How to find the longest contiuous subarray whose XOR is 0

For example, given {1,1,2,2}: the XOR of these subarrays are all 0: {1,1} , {2,2} , {1,1,2,2}. The length of the longest is 4. Find the length of the longest subarray and return the beginning and end index of this subarray.
-1
votes
1 answer

Longest Common Subsequence of Three Sequences of int

I am tring to solve the Longest Common Subsequence of Three Sequences of int using C++. the problem is a classic: Task. Given three sequences A = (a1, a2, . . . , an), B = (b1, b2, . . . , bm), and C = (c1, c2, . . . , cl), find the length of…
carnote
  • 13
  • 4
-1
votes
1 answer

Python syntax that I don't seem to understand

So I'm looking at this python code to find the longest subsequence of two strings but I don't understand "#line A" why the third parameter is key=len. From what I learnt len is a function which returns the length of a string but I don't understand…
Paker
  • 19
  • 5
-1
votes
1 answer

Longest Increasing Subsequence optimization

The Longest Increasing Subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order and in which the subsequence is as long as possible. Here is my O(n^2) approach which is running very…
Atinesh
  • 1,790
  • 9
  • 36
  • 57
-1
votes
1 answer

Wrong solution for distinct Sub-sequences of a sequence

I am trying to solve this problem. Problem is: 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 none)…
noman pouigt
  • 906
  • 11
  • 25
-1
votes
2 answers

Subsequence calculator. Can i make it more efficient?

The idea of subsequences is explained very well in this post:Generate subsequences But i didnt understand the answers on that question because im a beginner. What i wanted to know is if i could make my C program any more efficient while still…
riegour
  • 25
  • 5
-1
votes
1 answer

Integer Pattern

Below is how the solution should look like. Enter Y : 239847239 Enter X : 847 X is substring of Y Enter Y : 239847239 Enter X : 3923 X is subsequence of Y Enter Y : 239847239 Enter X : 489 X is neither substring nor subsequence of Y and…
-1
votes
3 answers

Algorithm: NON-contiguous subsequence with the sum no greater than and NEAREST to a given value

Problem: Given an integers array A[], length = n and a given integer value TARGET. Find the subsequence (might not be contiguous) satisfied that its sum is less than TARGET and nearest to that TARGET. Eg.: A[] = [10, -2, 3, 7]. TARGET = 14. Answer =…
Arcobaleno
  • 484
  • 1
  • 5
  • 14
-2
votes
1 answer

String Subsequence Matching

Given an array of string words, please design a string subsequence matcher. Implement the SubsequenceMatcher class: SubsequenceMatcher(string words[]): Initializes the object with a pattern array words, and an empty string s. bool addChar(char c):…
ZelKnow
  • 1
  • 2
-2
votes
1 answer

How to get a substring by deleting minimum number of characters?

In this question, we take 2 strings as input say s1 and s2. Now, first we need to check if s2 is a subsequence of s1. If not, print no. But if it is, we need to print the minimum number of characters to be deleted from s1 to get s2. Eg- thistext…
-2
votes
1 answer

Fast way of finding all numbers X that sum with themselves with one digit removed to get N?

I'm working on an assignment that gives an integer N and tasks us to find all possible combinations of X, Y such that X + Y = N and Y = X with one digit removed. For example, 302 would have the following solutions: 251 + 51 = 302 275 + 27 = 302 276…
-2
votes
1 answer

RegEx to not to contain "--"

I want to validate a string with alpha numeric values, but if the string contains -- (double dash) anywhere in the string, it should be…
Sandun Perera
  • 541
  • 6
  • 21
-2
votes
1 answer

Why am I finding the longest increasing subsequence instead of the longest decreasing subsequence?

I'm trying to look for the longest decreasing subsequence in an array in O(nlogn). Not sure whether this really takes O(nlogn), but anyways this returns the length of the longest increasing subsequence instead of the longest decreasing subsequence.…
yoyo_24
  • 13
  • 6