Every state is represented by string of length 2. For example DL is used for Delhi, HP for Himachal Pradesh, UP for Uttar Pradesh, PB for Punjab etc.
Given a string str consisting of uppercase English alphabets only, the task is to find the number of distinct state codes that appear in the string as contiguous sub-strings.
Input: str = “UPBRC”
UP, PB, BR and RC are 4 different state codes that appear in string as contiguous sub-strings.
Input: str = “UPUP”
UP and PU are the only state codes that appear in the given string.
Approach: Store every sub-string of length 2 in a set and finally return the size of the set which is the required number of distinct state codes appearing in the given string as sub-strings.
Below is the implementation of the above approach:
- Find distinct characters in distinct substrings of a string
- Contiguous subsegments of a string having distinct subsequent characters
- Minimum changes to a string to make all substrings distinct
- Count of distinct substrings of a string using Suffix Array
- Count of distinct substrings of a string using Suffix Trie
- Contiguous unique substrings with the given length L
- Count distinct substrings that contain some characters at most k times
- Count number of substrings with exactly k distinct characters
- Count number of distinct substrings of a given length
- Final state of the string after modification
- Maximum contiguous 1 possible in a binary string after k rotations
- Replace two substrings (of a string) with each other
- Number of substrings of a string
- Sum of all substrings of a string representing a number | Set 1
- Program to print all substrings of a given string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.