Tag: strings
-
Data Structures & Algorithms in Java – Strings – Encode and Decode Strings
Problem: Given a list of strings , encode them and then decode them back. Consider the use case where you want to send a list of strings over the network. You have the limitation of using only string data structure. And somehow you need to represent the list of strings as a string and then…
-
Data Structures & Algorithms in Java – Strings – Longest Palindromic Substring
Problem: Given a string , find the longest palindromic substring in that string. For example , for the input “babad” the longest palindromic substring is “bab” or “aba”. For the input “cbbd” the longest palindromic substring is “bb” Assumptions: The string has at least one character and at the most 1000 characters The string consists…
-
Data Structures & Algorithms in Java – Strings – Minimum Window Substring
Problem: Given two strings s and t , find the minimum window substring from s which contains all the characters of the string t. For example, For the input strings s = “ADOBECODEBANC” t = “ABC” The minimum window substring in s is “BANC” The possible substrings are “ADOBEC” , “BECODEBA” , “CODEBA” and “BANC”…
-
Data Structures & Algorithms in Java – Strings – Longest Repeating Character Replacement
Problem: Given a string and a number k find the longest substring whose characters can be replaced by the most repeating character to a maximum of k times. Example: Given string = “ABAB” and k = 2 You can replace the substring “ABAB” with “BBBB” since the two A’s are not the most repeating character…