Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a string **s** consisting of uppercase and lowercase alphabetic characters. Return the number of distinct substrings of size 2 that appear in** s** as contiguous substrings.

**Example**

**Input **:
s = "ABCAB"
**Output **:
3
**Explanation**: For "ABCAB", the
three distinct substrings of size
2 are "AB", "BC" and "CA".

**Example**

**Input **:
s = "XYZ"
**Output **:
2
**Explanation**: For "XYZ", the
two distinct substrings of size 2 are
"XY" and "YZ".

**Your Task** :

You don't need to read input or print anything. You have to complete the function *fun() *which takes the string** s** as input parameter and returns the number of distinct contiguous substring of size 2.

**Expected Time Complexity **: O(|s|)

**Expected Auxilliary Space** : O(|s|)

**Constraints**:

1<=|s|<=100

|s| denotes the length of the string s.

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

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?

YesLoading...

Distinct Substrings

...