Iam_Sandeep

Untitled

Nov 25th, 2025
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1.  
  2.  
  3. class Solution {
  4.  
  5.     public int longestSubsequenceInSubString(String x, String y) {
  6.         int n = x.length();
  7.         int m = y.length();
  8.  
  9.         int[][] dp = new int[n + 1][m + 1];
  10.         int maxLength = 0;
  11.  
  12.         for (int i = 1; i <= n; i++) {
  13.             for (int j = 1; j <= m; j++) {
  14.                
  15.                 if (Character.toLowerCase(x.charAt(i - 1)) == Character.toLowerCase(y.charAt(j - 1))) {
  16.                     dp[i][j] = dp[i - 1][j - 1] + 1;
  17.                 } else {
  18.                     dp[i][j] = 0;
  19.                 }
  20.  
  21.                 if (dp[i][j] > maxLength) {
  22.                     maxLength = dp[i][j];
  23.                 }
  24.             }
  25.         }
  26.  
  27.         return maxLength;
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment