Append Characters to String to Make Subsequence Problem

Problem You are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s. A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. Examples Example 1: ...

Longest Consecutive Sequence Problem

Problem Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Examples Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. ...

Longest Common Subsequence LCS 1 - Get Length

Problem Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings. ...

Longest Common Subsequence LCS 2 - Get Subsequence

Problem Given two sequences, return the longest subsequence present in both of them. Examples Example 1: Input: text1 = "abcde", text2 = "ace" Output: "ace" Explanation: The longest common subsequence is "ace". Example 2: Input: text1 = "abc", text2 = "abc" Output: "abc" Explanation: The longest common subsequence is "abc". ...

Is Subsequence Problem

Problem Given two strings s and t, return true if s is a subsequence of t, or false otherwise. OR Given two strings str1 and str2, find if str1 is a subsequence of str2. Subarrays vs Subsequences vs Subsets Definition Follow up Expected time complexity is linear. Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code? Examples Example 1: ...

Subarrays vs Subsequences vs Subsets Definition

Definitions A subarray is a contiguous part of array and maintains relative ordering of elements. For an array/string of size n, there are n*(n+1)/2 non-empty subarrays/substrings. A subsequence maintain relative ordering of elements but may or may not be a contiguous part of an array. For a sequence of size n, we can have 2^n-1 non-empty sub-sequences in total. A subset MAY NOT maintain relative ordering of elements and can or cannot be a contiguous part of an array. For a set of size n, we can have (2^n) sub-sets in total. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy