Back to Cosmos

cosmos

code/unclassified/src/biggest_suffix/readme.md

latest945 B
Original Source

cosmos

Your personal library of every algorithm and data structure code that you will ever encounter

Biggest Suffix

The aim is to find the biggest suffix of two strings where the strings are taken as input from the user.

Algorithm

After taking both the strings as input we find the length of the smaller string because we only need to compare that many characters in both the strings. After finding the length of the smaller string we start traversing from end of both the strings and check if they are same. If yes, we increase the counter. Else, we break the loop and print the string traversed so far.

Exampler

Few examples are:

  • s1 = "abcdef" , s2 = "def" : Biggest Suffix = "def"
  • s1 = "abc" , s2 = "abc" : Biggest Suffix = "abc"
  • s1 = "abcdef" , s2 = "abc" : Biggest Suffix = ""

<p align="center"> A massive collaborative effort by <a href="https://github.com/OpenGenus/cosmos">OpenGenus Foundation</a> </p>