Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

Leetcode Longest Uncommon Subsequence I problem solution

YASH PAL, 31 July 2024

In this Leetcode Longest Uncommon Subsequence I problem solution we have Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.

An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.

A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

For example, “abc” is a subsequence of “aebdc” because you can delete the underlined characters in “aebdc” to get “abc”. Other subsequences of “aebdc” include “aebdc”, “aeb”, and “” (empty string).

leetcode Longest Uncommon Subsequence I problem solution

Problem solution in Python.

class Solution:
    def findLUSlength(self, A: str, B: str) -> int:
        if A == B:
            return -1
        return max(len(A), len(B))

Problem solution in Java.

class Solution {
    public int findLUSlength(String a, String b) {
        if(a.equals(b)){
            return -1;
        }
        return Math.max(a.length(),b.length());
    }
}

Problem solution in C++.

class Solution {
public:
     int findLUSlength(string a, string b) {
        
        if(a == b) return -1;
        
        int x = a.length();
        int y = b.length();
        return (x>y ) ? x : y ; 
    }
};

Problem solution in C.

int findLUSlength(char* a, char* b) {
    if(!a && !b)
        return 0;
    if(strcmp(a, b) != 0)
        if(strlen(a) >= strlen(b))
            return strlen(a);
        else 
            return strlen(b);
    return -1;
}

coding problems solutions Leetcode Problems Solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes