FastPrepLongest Common Subsequence Length
Problems/Longest Common Subsequence Length

Longest Common Subsequence Length

Zscaler logoZscaler● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names longest common subsequence for two strings but does not choose between the length and rebuilding the subsequence, or give an interface and limits. Our version is about 65% the same as the reported question.

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) → int

Examples

Example 1

first = "abcde"second = "ace"return = 3

The subsequence ace appears in both strings.

Example 2

first = "abc"second = "def"return = 0

The strings have no character in common.

Example 3

first = ""second = "abc"return = 0

An 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

Interview reports that mention this question

  • Zscaler SDE C++ and OS Rounds: 7 Experiences (Part 2 of 6)
  • Zscaler Campus SDE Interviews: 37 Experiences (Part 1 of 6)

Zscaler interview experiences

  • Zscaler Campus Drive Interviews: 4 Experiences (Part 6 of 6)
  • Zscaler Java, QA and Cloud Rounds: 8 Experiences (Part 5 of 6)
  • Zscaler UI and DevTest Rounds: 8 Experiences (Part 4 of 6)
  • Zscaler Intern, QA and SRE Rounds: 7 Experiences (Part 3 of 6)
All Zscaler interview questionsSee Zscaler hiring insights
Saved
class Solution {
    public int longestCommonSubsequence(String first, String second) {
      // write your code here
    }
}
Checking account…