Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

Given two strings X and Y of lengths m and n respectively, find the length of the smallest string which has both, X and Y as its sub-sequences.

Note: X and Y can have both uppercase and lowercase letters.

**Example 1**

**Input:
**X = abcd, Y = xycd
**Output: **6**
Explanation: **Shortest Common Supersequence
would be abxycd which is of length 6 and
has both the strings as its subsequences.

**Example 2**

**Input:
**X = efgh, Y = jghi
**Output: **6**
Explanation: **Shortest Common Supersequence
would be ejfghi which is of length 6 and
has both the strings as its subsequences.

**Your Task:**

Complete **shortestCommonSupersequence()** function that takes X, Y, m, and n as arguments and returns the length of the required string.

**Expected Time Complexity: **O(Length(X) * Length(Y)).

**Expected Auxiliary Space: **O(Length(X) * Length(Y)).

**Constraints:**

1<= |X|, |Y| <= 100

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Shortest Common Supersequence

...