Sort a Stack using Recursion

In this problem, We have to write a code to sort a stack using recursion. We have to sort in a descending order (Top of the stack has the greatest element).

We don’t have to use any loop constructs ( for, while etc) or additional data structure.

For Example –

In this example, You can see after sorting the stack, the element which has greater value is at the top of the stack.

Sort a stack using recursion

Check If a String is Subsequence of Another String

In this tutorial, I am going to discuss a problem Is Subsequence (check if a string is subsequence of another string).

Given two strings str1 and str2, check if str1 is a subsequence of str2. Both strings consists only of lowercase characters.

Example 1:

Input: str1 = “abc”, str2 = “ahbgdc”

Output: true

Example 2:

Input: s = “axc”, t = “ahbgdc”

Output: false