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:
- 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
- Count distinct substrings that contain some characters at most k times
- Count number of distinct substrings of a given length
- Count number of substrings with exactly k distinct characters
- Final state of the string after modification
- Maximum contiguous 1 possible in a binary string after k rotations
- Number of substrings of a string
- Replace two substrings (of a string) with each other
- Count of substrings of a binary string containing K ones
- Number of even substrings in a string of digits
- Different substrings in a string that start and end with given strings
- Number of substrings of one string present in other
- Lexicographical concatenation of all substrings of a 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.