Longest Common Subsequence Length
Updated
Problem statement
Given two lowercase strings first and second, return the length of their longest common subsequence.
A subsequence is formed by deleting zero or more characters without changing the relative order of the remaining characters. A common subsequence appears in both strings; its characters do not need to be consecutive.
Function
longestCommonSubsequence(first: String, second: String) → intExamples
Example 1
first = "abcde"second = "ace"return = 3The subsequence ace appears in both strings.
Example 2
first = "abc"second = "def"return = 0The strings have no character in common.
Example 3
first = ""second = "abc"return = 0An empty string has no nonempty subsequence.
Constraints
0 <= first.length, second.length <= 1000- Both strings contain only lowercase English letters.
More Zscaler interview questions
- Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
- Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
- Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
- Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
- Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
- Merging PalindromesPHONE SCREEN · Seen Sep 2024
- Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
- Merge IntervalsPHONE SCREEN · Seen Jun 2024
- Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024
- How Many Sentences? 🌿OA · Seen Mar 2024
Similar questions at other companies
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word BreakGoogle · ONSITE INTERVIEWGoogle interview questions
- Reconstruct One Sentence From a DictionaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Decode Numeric StringArcesium · ONSITE INTERVIEWArcesium interview questions
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Minimum Steps on a Circular Character DialNavan · ONSITE INTERVIEWNavan interview questions