Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Longest Uncommon Subsequence I problem solution

YASH PAL, 31 July 202422 January 2026

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

Leetcode Longest Uncommon Subsequence I 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))

Longest Uncommon Subsequence I 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 Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes