Class StringUtil

java.lang.Object
org.drip.service.common.StringUtil

public class StringUtil
extends java.lang.Object
StringUtil implements string utility functions. It exports the following functions:
  • Decompose + Transform string arrays into appropriate target type set/array/list, and vice versa
  • General-purpose String processor functions, such as GUID generator, splitter, type converter and input checker




Author:
Lakshmi Krishnamurthy
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String NULL_SER_STRING
    Null serialized string
    static double VERSION
    Serialization Version - ALWAYS prepend this on all derived classes
  • Constructor Summary

    Constructors
    Constructor Description
    StringUtil()  
  • Method Summary

    Modifier and Type Method Description
    static int AToI​(java.lang.String s)
    Implement atoi which converts a string to an integer.
    static int BalanceString​(java.lang.String s)
    Given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'.
    static boolean BooleanListFromString​(java.util.List<java.lang.Boolean> lsb, java.lang.String strList, java.lang.String strDelim)
    Create a list of booleans from a delimited string
    static int ClosestPalindromicInteger​(int i)
    Given an integer n, find the closest integer (not including itself), which is a palindrome.
    static java.util.List<java.lang.String> CollectSameCharacters​(java.lang.String s)
    Given a string s of lower-case letters, partition s into as many as parts so that one letter only appear in one part.
    static java.util.List<java.lang.String> ConditionalWordList​(java.lang.String s)
    Given a string s of lower-case letters, find as many sub-strings as possible that meet the following criteria: - no overlap among strings - one letter can only exist in one string.
    static java.lang.String ConstrainedWord​(int a, int b, int c)
    Given a, b, c, find any string of maximum length that can be created such that no 3 consecutive characters are same.
    static int DecimalNumberFromString​(java.lang.String s)
    Convert the String to a Number
    static java.lang.String DecodeStringAtIndex​(java.lang.String s, int k)
    An encoded string is given.
    static java.util.List<java.lang.String> FrequencyBasedWordDecomposition​(java.util.Map<java.lang.String,​java.lang.Integer> wordFrequencyMap, java.lang.String s)
    Break the given string into words, provided by a given hash-map of frequency of word as word : frequency.
    static java.util.List<java.util.List<java.lang.String>> GroupAnagrams​(java.lang.String[] wordArray)
    Given an array of words, group anagrams together.
    static java.util.List<java.util.List<java.lang.String>> GroupAnagrams2​(java.lang.String[] wordArray)
    Given an array of words, group anagrams together.
    static java.lang.String GUID()
    Generate a GUID string
    static java.lang.String InPlaceWordReversion​(java.lang.String s)
    Given an input string, reverse the order of the words.
    static boolean IntegerListFromString​(java.util.List<java.lang.Integer> lsi, java.lang.String strList, java.lang.String strDelim)
    Create a list of integers from a delimited string
    static int InvalidParenthesisMinimalAdd​(java.lang.String s)
    Given a string of '(' and ')' parentheses, add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid.
    static java.lang.String InvalidParenthesisMinimalRemove​(java.lang.String s)
    Given a string of '(' , ')' and lowercase English characters, remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.
    static boolean IsEmpty​(java.lang.String str)
    Indicate if the Input String is Empty
    static boolean IsPermutationPresent​(java.lang.String s1, java.lang.String s2)
    Is Permutation s2 Present in s1?
    static boolean IsValidPalindrome​(java.lang.String s)
    Given a non-empty string, you may delete at most one character.
    static boolean KeyValueListFromStringArray​(java.util.List<java.lang.Double> lsdblKey, java.util.List<java.lang.Double> lsdblValue, java.lang.String strArray, java.lang.String strRecordDelim, java.lang.String strKVDelim)
    Split the string array into pairs of key-value doubles and returns them
    static int LengthOfLongestNonRepeatingSubstring​(java.lang.String s)
    Find the length of the longest substring without repeating characters.
    static java.lang.String LongestDistinctSubstring​(java.lang.String s)
    Generate the Longest Distinct Substring
    static java.lang.String LongestNonRepeatingSubstring​(java.lang.String s)
    Given a string, find the length of the longest substring without repeating characters.
    static java.lang.String LongestPalindromeSubstring​(java.lang.String s)
    Given a string, find the longest palindromic substring in it.
    static java.lang.String LongestPalindromicSubstring​(java.lang.String s)
    Given a string, find the longest palindromic substring.
    static java.lang.String LongestVowel​(java.lang.String s)
    Given a string of lower characters, remove at most two substrings of any length from the given string such that the remaining string contains vowels('a','e','i','o','u') only.
    static void main​(java.lang.String[] argumentArray)
    Entry Point
    static double[] MakeDoubleArrayFromStringTokenizer​(java.util.StringTokenizer stdbl)
    Make an array of double from a string tokenizer
    static int[] MakeIntegerArrayFromStringTokenizer​(java.util.StringTokenizer st)
    Make an array of Integers from a string tokenizer
    static java.lang.String MakeStringArg​(java.lang.String strArg)
    Format the given string parameter into an argument
    static int MatchingPairCount​(java.lang.String s, java.lang.String t)
    Count the Number of Matching Pairs of t in s
    static boolean MatchInStringArray​(java.lang.String[] astrFieldToMatch, java.lang.String[] astrMatchSet, boolean bCaseMatch)
    Look for a match of the field in the field set to an entry in the input array
    static boolean MatchInStringArray​(java.lang.String strFieldToMatch, java.lang.String[] astrMatchSet, boolean bCaseMatch)
    Look for a match of the field in the input array
    static int MaximumPalindromeProductLength​(java.lang.String s)
    Compute the Maximum Palindrome Product Length
    static java.util.List<java.util.List<java.lang.String>> MergeAccountList​(java.util.List<java.util.List<java.lang.String>> accounts)
    Generate a List of Merged Accounts
    static java.lang.String MinimumWindowSubstring​(java.lang.String s, java.lang.String t)
    Retrieve the Minimum Window represented by t inside s
    static java.lang.String MultiplyNumbers​(java.lang.String num1, java.lang.String num2)
    Given two non-negative integers represented as strings, return their product, also represented as a string.
    static java.lang.String[] NearestCities​(java.lang.String[] cities, int[] xCoordinateArray, int[] yCoordinateArray, java.lang.String[] queryCities)
    Company A has Fulfillment Centers in multiple cities within a large geographic region.
    static java.lang.String NestedArrayDepthSum​(java.lang.String expression)
    Given Nested Array calculate the Depth Sum.
    static int NextGreaterInteger​(int n)
    Given a positive 32-bit integer, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer and is greater in value.
    static boolean ParseFromUnitaryString​(java.lang.String strUnitaryBoolean)
    Check if the string represents an unitary boolean
    static int PasswordChangeSteps​(java.lang.String password)
    Find the Minimum of Steps to Make the Password Valid
    static java.util.Set<java.lang.String> PermutationSet​(java.lang.String s)
    Generate the Set of all Permutation Sub-strings
    static java.lang.String ProcessInputForNULL​(java.lang.String strIn, boolean bEmptyToNULL)
    Check the Input String to Check for NULL - and return it
    static java.lang.String RemoveMinimumValidParenthesis​(java.lang.String s)
    Trim out the Minimal Valid Parenthesis
    static java.lang.String ReorganizeString​(java.lang.String in)
    Reorganize the given String
    static java.lang.String ReverseWords​(java.lang.String s)
    Given an input string, reverse the string word by word.
    static java.lang.String RotationalCipher​(java.lang.String in, int rotationFactor)
    One simple way to encrypt a string is to "rotate" every alphanumeric character by a certain amount.
    static java.util.List<java.lang.String> ShortestWordTransformationSequence​(java.util.List<java.lang.String> wordList, java.lang.String beginWord, java.lang.String endWord)
    A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ...
    static java.lang.String SimplifyPath​(java.lang.String path)
    Given an absolute path for a file (Unix-style), simplify it.
    static int solution​(int[] A)
    Compute the Sum of the Integers
    static java.lang.String[] Split​(java.lang.String inputPhrase, java.lang.String delimiter)
    Parse and Split the Input Phrase into a String Array using the specified Delimiter
    static java.util.List<java.util.List<java.lang.String>> SplitIntoUniquePrimes​(java.lang.String number)
    A company's operations team needs an algorithm that can break out a list of products for a given order.
    static java.lang.String StringArrayToString​(java.lang.String[] astr, java.lang.String strRecordDelimiter, java.lang.String strNULL)
    Convert the String Array to a Record Delimited String
    static boolean StringMatch​(java.lang.String strLeft, java.lang.String strRight)
    Indicate it the pair of Strings Match each other in Value
    static java.lang.String ThreeDigitNumber​(int i)
    Convert the Number to String
    static java.lang.String ToString​(boolean flag)
    Convert the Boolean Flag to String
    static boolean ValidateNumber​(java.lang.String s)
    A valid number can be split up into these components (in order): A decimal number or an integer.
    static boolean ValidateParenthesis​(java.lang.String input)
    Indicate if the Input String is composed of Valid Parenthesis Sequence
    static boolean ValidateParenthesisString​(java.lang.String s)
    Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid.
    static java.lang.String ValidIPAddressType​(java.lang.String s)
    Function to check whether an input string is a valid IPv4 address or IPv6 address or neither.
    static int VersionCompare​(java.lang.String version1, java.lang.String version2)
    Compare two version numbers version1 and version2.
    static boolean WildcardPatternMatchingValidation​(java.lang.String s, java.lang.String p)
    Validate the Wild-card Pattern Match
    static java.util.List<java.lang.Integer> WordConcatenationStartList​(java.lang.String full, java.util.Set<java.lang.String> subset)
    Generate the List of Word Concatenation Start

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NULL_SER_STRING

      public static final java.lang.String NULL_SER_STRING
      Null serialized string
      See Also:
      Constant Field Values
    • VERSION

      public static final double VERSION
      Serialization Version - ALWAYS prepend this on all derived classes
      See Also:
      Constant Field Values
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • DecimalNumberFromString

      public static final int DecimalNumberFromString​(java.lang.String s)
      Convert the String to a Number
      Parameters:
      s - Input String
      Returns:
      The Number
    • MatchInStringArray

      public static final boolean MatchInStringArray​(java.lang.String strFieldToMatch, java.lang.String[] astrMatchSet, boolean bCaseMatch)
      Look for a match of the field in the input array
      Parameters:
      strFieldToMatch - Field To Match
      astrMatchSet - Array of fields to compare with
      bCaseMatch - TRUE - Match case
      Returns:
      TRUE - Match found according to the criteria specified
    • MatchInStringArray

      public static final boolean MatchInStringArray​(java.lang.String[] astrFieldToMatch, java.lang.String[] astrMatchSet, boolean bCaseMatch)
      Look for a match of the field in the field set to an entry in the input array
      Parameters:
      astrFieldToMatch - Field Array To Match
      astrMatchSet - Array of fields to compare with
      bCaseMatch - TRUE - Match case
      Returns:
      TRUE - Match found according to the criteria specified
    • MakeStringArg

      public static final java.lang.String MakeStringArg​(java.lang.String strArg)
      Format the given string parameter into an argument
      Parameters:
      strArg - String Argument
      Returns:
      Parameter from the Argument
    • ProcessInputForNULL

      public static final java.lang.String ProcessInputForNULL​(java.lang.String strIn, boolean bEmptyToNULL)
      Check the Input String to Check for NULL - and return it
      Parameters:
      strIn - Input String
      bEmptyToNULL - TRUE if Empty String needs to be converted to NULL
      Returns:
      The Processed String
    • Split

      public static final java.lang.String[] Split​(java.lang.String inputPhrase, java.lang.String delimiter)
      Parse and Split the Input Phrase into a String Array using the specified Delimiter
      Parameters:
      inputPhrase - Input Phrase
      delimiter - Delimiter
      Returns:
      Array of Sub-Strings
    • ParseFromUnitaryString

      public static final boolean ParseFromUnitaryString​(java.lang.String strUnitaryBoolean)
      Check if the string represents an unitary boolean
      Parameters:
      strUnitaryBoolean - String input
      Returns:
      TRUE - Unitary Boolean
    • MakeIntegerArrayFromStringTokenizer

      public static final int[] MakeIntegerArrayFromStringTokenizer​(java.util.StringTokenizer st)
      Make an array of Integers from a string tokenizer
      Parameters:
      st - Tokenizer containing delimited doubles
      Returns:
      Double array
    • MakeDoubleArrayFromStringTokenizer

      public static final double[] MakeDoubleArrayFromStringTokenizer​(java.util.StringTokenizer stdbl)
      Make an array of double from a string tokenizer
      Parameters:
      stdbl - Tokenizer containing delimited doubles
      Returns:
      Double array
    • GUID

      public static final java.lang.String GUID()
      Generate a GUID string
      Returns:
      String representing the GUID
    • KeyValueListFromStringArray

      public static final boolean KeyValueListFromStringArray​(java.util.List<java.lang.Double> lsdblKey, java.util.List<java.lang.Double> lsdblValue, java.lang.String strArray, java.lang.String strRecordDelim, java.lang.String strKVDelim)
      Split the string array into pairs of key-value doubles and returns them
      Parameters:
      lsdblKey - [out] List of Keys
      lsdblValue - [out] List of Values
      strArray - [in] String containing KV records
      strRecordDelim - [in] Record Delimiter
      strKVDelim - [in] Key-Value Delimiter
      Returns:
      True if parsing is successful
    • IntegerListFromString

      public static final boolean IntegerListFromString​(java.util.List<java.lang.Integer> lsi, java.lang.String strList, java.lang.String strDelim)
      Create a list of integers from a delimited string
      Parameters:
      lsi - [Output] List of Integers
      strList - Delimited String input
      strDelim - Delimiter
      Returns:
      True if successful
    • BooleanListFromString

      public static final boolean BooleanListFromString​(java.util.List<java.lang.Boolean> lsb, java.lang.String strList, java.lang.String strDelim)
      Create a list of booleans from a delimited string
      Parameters:
      lsb - [Output] List of Booleans
      strList - Delimited String input
      strDelim - Delimiter
      Returns:
      True if successful
    • StringArrayToString

      public static final java.lang.String StringArrayToString​(java.lang.String[] astr, java.lang.String strRecordDelimiter, java.lang.String strNULL)
      Convert the String Array to a Record Delimited String
      Parameters:
      astr - Input String Array
      strRecordDelimiter - The String Record Delimiter
      strNULL - NULL String Indicator
      Returns:
      The Record Delimited String Array
    • IsEmpty

      public static final boolean IsEmpty​(java.lang.String str)
      Indicate if the Input String is Empty
      Parameters:
      str - The Input String
      Returns:
      TRUE - The Input String is Empty
    • StringMatch

      public static final boolean StringMatch​(java.lang.String strLeft, java.lang.String strRight)
      Indicate it the pair of Strings Match each other in Value
      Parameters:
      strLeft - The Left String
      strRight - The Right String
      Returns:
      TRUE - The Strings Match
    • AToI

      public static final int AToI​(java.lang.String s)
      Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in s is not a valid integral number, or if no such sequence exists because either s is empty or it contains only whitespace characters, no conversion is performed. If no valid conversion could be performed, a zero value is returned. Note: Only the space character ' ' is considered as whitespace character. Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [-10^231, 10^231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (-10^231) or INT_MIN (10^231 - 1) is returned.
      Parameters:
      s - Input String
      Returns:
      The Integer
    • ReverseWords

      public static final java.lang.String ReverseWords​(java.lang.String s)
      Given an input string, reverse the string word by word.
      Parameters:
      s - Input String
      Returns:
      String with Words Reversed
    • ValidIPAddressType

      public static final java.lang.String ValidIPAddressType​(java.lang.String s)
      Function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots ("."), e.g.,172.16.254.1; Besides, leading zeros in the IPv4 is invalid. For example, the address 172.16.254.01 is invalid. IPv6 addresses are represented as eight groups of four hexadecimal digits, each group representing 16 bits. The groups are separated by colons (":"). For example, the address 2001:0db8:85a3:0000:0000:8a2e:0370:7334 is a valid one. Also, we could omit some leading zeros among four hexadecimal digits and some low-case characters in the address to upper-case ones, so 2001:db8:85a3:0:0:8A2E:0370:7334 is also a valid IPv6 address(Omit leading zeros and using upper cases). However, we don't replace a consecutive group of zero value with a single empty group using two consecutive colons (::) to pursue simplicity. For example, 2001:0db8:85a3::8A2E:0370:7334 is an invalid IPv6 address. Besides, extra leading zeros in the IPv6 is also invalid. For example, the address 02001:0db8:85a3:0000:0000:8a2e:0370:7334 is invalid. Note: You may assume there is no extra space or special characters in the input string.
      Parameters:
      s - Input String
      Returns:
      IP Address Type
    • VersionCompare

      public static final int VersionCompare​(java.lang.String version1, java.lang.String version2)
      Compare two version numbers version1 and version2. If version1 gt version2 return 1; if version1 lt version2 return -1;otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not represent a decimal point and is used to separate number sequences. For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision. You may assume the default revision number for each level of a version number to be 0. For example, version number 3.4 has a revision number of 3 and 4 for its first and second level revision number. Its third and fourth level revision number are both 0.
      Parameters:
      version1 - First Version String
      version2 - Second Version String
      Returns:
      Results of the Comparison
    • LongestPalindromicSubstring

      public static final java.lang.String LongestPalindromicSubstring​(java.lang.String s)
      Given a string, find the longest palindromic substring.
      Parameters:
      s - Input String
      Returns:
      The Longest Palindromic substring
    • LengthOfLongestNonRepeatingSubstring

      public static final int LengthOfLongestNonRepeatingSubstring​(java.lang.String s)
      Find the length of the longest substring without repeating characters.
      Parameters:
      s - Input String
      Returns:
      Length of the longest substring without repeating characters.
    • ValidateParenthesisString

      public static final boolean ValidateParenthesisString​(java.lang.String s)
      Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules: Any left parenthesis '(' must have a corresponding right parenthesis ')'. Any right parenthesis ')' must have a corresponding left parenthesis '('. Left parenthesis '(' must go before the corresponding right parenthesis ')'. '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string. An empty string is also valid.
      Parameters:
      s - Input String
      Returns:
      TRUE - The String has Valid Parenthesis
    • NextGreaterInteger

      public static final int NextGreaterInteger​(int n)
      Given a positive 32-bit integer, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer and is greater in value. If no such positive 32-bit integer exists, you need to return -1.
      Parameters:
      n - Input Integer
      Returns:
      Next Greater Number
    • SimplifyPath

      public static final java.lang.String SimplifyPath​(java.lang.String path)
      Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period .. moves the directory up a level. Note that the returned canonical path must always begin with a slash /, and there must be only a single slash / between two directory names. The last directory name (if it exists) must not end with a trailing /. Also, the canonical path must be the shortest string representing the absolute path.
      Parameters:
      path - Input Path
      Returns:
      Simplified Path
    • BalanceString

      public static final int BalanceString​(java.lang.String s)
      Given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string is said to be balanced if each of its characters appears n/4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same length to make the original string balanced. Return 0 if the string is already balanced.
      Parameters:
      s - Input String
      Returns:
      Minimum length of the substring
    • MultiplyNumbers

      public static final java.lang.String MultiplyNumbers​(java.lang.String num1, java.lang.String num2)
      Given two non-negative integers represented as strings, return their product, also represented as a string.
      Parameters:
      num1 - First Number
      num2 - Second Number
      Returns:
      The Product
    • RotationalCipher

      public static final java.lang.String RotationalCipher​(java.lang.String in, int rotationFactor)
      One simple way to encrypt a string is to "rotate" every alphanumeric character by a certain amount. Rotating a character means replacing it with another character that is a certain number of steps away in normal alphabetic or numerical order. For example, if the string "Zebra-493?" is rotated 3 places, the resulting string is "Cheud-726?". Every alphabetic character is replaced with the character 3 letters higher (wrapping around from Z to A), and every numeric character replaced with the character 3 digits higher (wrapping around from 9 to 0). Note that the non-alphanumeric characters remain unchanged. Given a string and a rotation factor, return an encrypted string.
      Parameters:
      in - Input String
      rotationFactor - Rotation Factor
      Returns:
      The Encrypted String
    • MatchingPairCount

      public static final int MatchingPairCount​(java.lang.String s, java.lang.String t)
      Count the Number of Matching Pairs of t in s
      Parameters:
      s - s
      t - t
      Returns:
      Count of the Number of Matching Pairs of t in s
    • MinimumWindowSubstring

      public static final java.lang.String MinimumWindowSubstring​(java.lang.String s, java.lang.String t)
      Retrieve the Minimum Window represented by t inside s
      Parameters:
      s - s
      t - t
      Returns:
      The Minimum Window String represented by t inside s
    • IsValidPalindrome

      public static final boolean IsValidPalindrome​(java.lang.String s)
      Given a non-empty string, you may delete at most one character. Judge whether you can make it a palindrome.
      Parameters:
      s - Input String
      Returns:
      TRUE - Can be turned into a Palindrome with one Deletion
    • ClosestPalindromicInteger

      public static final int ClosestPalindromicInteger​(int i)
      Given an integer n, find the closest integer (not including itself), which is a palindrome. The 'closest' is defined as absolute difference minimized between two integers.
      Parameters:
      i - The Integer
      Returns:
      Closest Palindrome Integer
    • NestedArrayDepthSum

      public static final java.lang.String NestedArrayDepthSum​(java.lang.String expression)
      Given Nested Array calculate the Depth Sum.
      Parameters:
      expression - The Expression
      Returns:
      Value of the Nested Array Sum
    • DecodeStringAtIndex

      public static final java.lang.String DecodeStringAtIndex​(java.lang.String s, int k)
      An encoded string is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is a letter, that letter is written onto the tape. If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total. Now for some encoded string, and an index K, find and return the kth letter (1 indexed) in the decoded string.
      Parameters:
      s - Input String
      k - kth Location (1-indexed)
      Returns:
      kth letter (1 indexed) in the decoded string.
    • LongestPalindromeSubstring

      public static final java.lang.String LongestPalindromeSubstring​(java.lang.String s)
      Given a string, find the longest palindromic substring in it. You may assume that the maximum length of the string is 1000.
      Parameters:
      s - The Input String
      Returns:
      The Longest Palindrome Sub-string
    • LongestNonRepeatingSubstring

      public static final java.lang.String LongestNonRepeatingSubstring​(java.lang.String s)
      Given a string, find the length of the longest substring without repeating characters.
      Parameters:
      s - The Given String
      Returns:
      The Longest Non-repeating Sub-string
    • ThreeDigitNumber

      public static final java.lang.String ThreeDigitNumber​(int i)
      Convert the Number to String
      Parameters:
      i - Input Number
      Returns:
      The Converted String
    • ReorganizeString

      public static final java.lang.String ReorganizeString​(java.lang.String in)
      Reorganize the given String
      Parameters:
      in - Input String
      Returns:
      The Reorganized String
    • RemoveMinimumValidParenthesis

      public static final java.lang.String RemoveMinimumValidParenthesis​(java.lang.String s)
      Trim out the Minimal Valid Parenthesis
      Parameters:
      s - Input String
      Returns:
      The Trimmed out String
    • PermutationSet

      public static final java.util.Set<java.lang.String> PermutationSet​(java.lang.String s)
      Generate the Set of all Permutation Sub-strings
      Parameters:
      s - Input String
      Returns:
      Set of all Permutation Sub-strings
    • IsPermutationPresent

      public static final boolean IsPermutationPresent​(java.lang.String s1, java.lang.String s2)
      Is Permutation s2 Present in s1?
      Parameters:
      s1 - Master String
      s2 - Sub-string
      Returns:
      TRUE - Permutation s2 Present in s1
    • MergeAccountList

      public static final java.util.List<java.util.List<java.lang.String>> MergeAccountList​(java.util.List<java.util.List<java.lang.String>> accounts)
      Generate a List of Merged Accounts
      Parameters:
      accounts - List of Accounts
      Returns:
      List of Merged Accounts
    • solution

      public static final int solution​(int[] A)
      Compute the Sum of the Integers
      Parameters:
      A - Input Array
      Returns:
      Sum of the Integers
    • ValidateParenthesis

      public static final boolean ValidateParenthesis​(java.lang.String input)
      Indicate if the Input String is composed of Valid Parenthesis Sequence
      Parameters:
      input - Input String
      Returns:
      TRUE - The Input String is composed of Valid Parenthesis Sequence
    • LongestDistinctSubstring

      public static final java.lang.String LongestDistinctSubstring​(java.lang.String s)
      Generate the Longest Distinct Substring
      Parameters:
      s - Input String
      Returns:
      The Longest Distinct Substring
    • InvalidParenthesisMinimalRemove

      public static final java.lang.String InvalidParenthesisMinimalRemove​(java.lang.String s)
      Given a string of '(' , ')' and lowercase English characters, remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase characters, or It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be written as (A), where A is a valid string.
      Parameters:
      s - The Input String
      Returns:
      The Valid Parenthesis
    • InvalidParenthesisMinimalAdd

      public static final int InvalidParenthesisMinimalAdd​(java.lang.String s)
      Given a string of '(' and ')' parentheses, add the minimum number of parentheses ( '(' or ')', and in any positions ) so that the resulting parentheses string is valid. Formally, a parentheses string is valid if and only if: It is the empty string, or It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be written as (A), where A is a valid string. Given a parentheses string, return the minimum number of parentheses one must add to make the resulting string valid.
      Parameters:
      s - Input String
      Returns:
      Minimum Number of Parentheses to be added
    • FrequencyBasedWordDecomposition

      public static final java.util.List<java.lang.String> FrequencyBasedWordDecomposition​(java.util.Map<java.lang.String,​java.lang.Integer> wordFrequencyMap, java.lang.String s)
      Break the given string into words, provided by a given hash-map of frequency of word as word : frequency.
      Parameters:
      wordFrequencyMap - Word Frequency Map
      s - Input String
      Returns:
      Broken Down Sequence of Words
    • GroupAnagrams2

      public static final java.util.List<java.util.List<java.lang.String>> GroupAnagrams2​(java.lang.String[] wordArray)
      Given an array of words, group anagrams together.
      Parameters:
      wordArray - Array of Words
      Returns:
      The Anagram Group List
    • GroupAnagrams

      public static final java.util.List<java.util.List<java.lang.String>> GroupAnagrams​(java.lang.String[] wordArray)
      Given an array of words, group anagrams together.
      Parameters:
      wordArray - Array of Words
      Returns:
      The Anagram Group List
    • NearestCities

      public static final java.lang.String[] NearestCities​(java.lang.String[] cities, int[] xCoordinateArray, int[] yCoordinateArray, java.lang.String[] queryCities)
      Company A has Fulfillment Centers in multiple cities within a large geographic region. The cities are arranged on a graph that has been divided up like an ordinary Cartesian plane. Each city is located at an integral (x, y) coordinate intersection. City names and locations are given in the form of three arrays: c, x, and y, which are aligned by the index to provide the city name (c[i]), and its coordinates, (x[i], y[i]). Write an algorithm to determine the name of the nearest city that shares either an x or a y coordinate with the queried city. If no other cities share an xory coordinate, return NONE. If two cities have the same distance to the queried city, q[i], consider the one with an alphabetically smaller name (i.e. 'ab' lt 'aba' lt 'abb') as the closest choice. The distance is denoted on a Euclidean plane: the difference in x plus the difference in y.
      Parameters:
      cities - Array of Cities
      xCoordinateArray - Array of City X Coordinates
      yCoordinateArray - Array of City Y Coordinates
      queryCities - Cities to be Queried
      Returns:
      Array of the Nearest Cities
    • SplitIntoUniquePrimes

      public static final java.util.List<java.util.List<java.lang.String>> SplitIntoUniquePrimes​(java.lang.String number)
      A company's operations team needs an algorithm that can break out a list of products for a given order. The products in the order are listed as a string and the order items are represented as prime numbers. Given a string consisting of digits [0-9], count the number of ways the given string can be split into prime numbers, which represent unique items in the order. The digits must remain in the order given and the entire string must be used. Write an algorithm to find the number of ways the given string can be split into unique prime numbers using the entire string.
      Parameters:
      number - The Input Number
      Returns:
      The Sequence List of Unique Primes
    • CollectSameCharacters

      public static final java.util.List<java.lang.String> CollectSameCharacters​(java.lang.String s)
      Given a string s of lower-case letters, partition s into as many as parts so that one letter only appear in one part. Return the partitions as a list.
      Parameters:
      s - The Input String
      Returns:
      List of Same Character Partitions
    • LongestVowel

      public static final java.lang.String LongestVowel​(java.lang.String s)
      Given a string of lower characters, remove at most two substrings of any length from the given string such that the remaining string contains vowels('a','e','i','o','u') only. Your aim is to maximize the length of the remaining string. Output the length of remaining string after removal of at most two substrings.
      Parameters:
      s - Input String
      Returns:
      Longest String after Removal
    • ConstrainedWord

      public static final java.lang.String ConstrainedWord​(int a, int b, int c)
      Given a, b, c, find any string of maximum length that can be created such that no 3 consecutive characters are same. There can be at max a 'a', b 'b' and c 'c'.
      Parameters:
      a - Count of the Number of 'A's
      b - Count of the Number of 'B's
      c - Count of the Number of 'C's
      Returns:
      The Longest Word
    • ConditionalWordList

      public static final java.util.List<java.lang.String> ConditionalWordList​(java.lang.String s)
      Given a string s of lower-case letters, find as many sub-strings as possible that meet the following criteria: - no overlap among strings - one letter can only exist in one string. For every letter c in the sub-string, all instances of c must also be in the sub-string - find as many sub-strings as possible - if there are two solutions with the same number of sub-strings, return the one with the smaller total length. Return sub-strings as a list.
      Parameters:
      s - Input String
      Returns:
      The Conditional Word List
    • MaximumPalindromeProductLength

      public static final int MaximumPalindromeProductLength​(java.lang.String s)
      Compute the Maximum Palindrome Product Length
      Parameters:
      s - Inout String
      Returns:
      Maximum Palindrome Product Length
    • WordConcatenationStartList

      public static final java.util.List<java.lang.Integer> WordConcatenationStartList​(java.lang.String full, java.util.Set<java.lang.String> subset)
      Generate the List of Word Concatenation Start
      Parameters:
      full - The Full Word
      subset - The Set of sub-words
      Returns:
      The List of Word Concatenation Start
    • PasswordChangeSteps

      public static final int PasswordChangeSteps​(java.lang.String password)
      Find the Minimum of Steps to Make the Password Valid
      Parameters:
      password - The Input Password
      Returns:
      The Minimum of Steps to Make the Password Valid
    • ValidateNumber

      public static final boolean ValidateNumber​(java.lang.String s)
      A valid number can be split up into these components (in order): A decimal number or an integer. (Optional) An 'e' or 'E', followed by an integer. A decimal number can be split up into these components (in order): (Optional) A sign character (either '+' or '-'). One of the following formats: One or more digits, followed by a dot '.'. One or more digits, followed by a dot '.', followed by one or more digits. A dot '.', followed by one or more digits. An integer can be split up into these components (in order): (Optional) A sign character (either '+' or '-'). One or more digits. For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"]. Given a string s, return true if s is a valid number.
      Parameters:
      s - The Input Number
      Returns:
      TRUE - Number is Valid
    • ShortestWordTransformationSequence

      public static final java.util.List<java.lang.String> ShortestWordTransformationSequence​(java.util.List<java.lang.String> wordList, java.lang.String beginWord, java.lang.String endWord)
      A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every adjacent pair of words differs by a single letter. Every si for 1 leq i leq k is in wordList. Note that beginWord does not need to be in wordList. sk == endWord Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists. Each sequence should be returned as a list of the words [beginWord, s1, s2, ..., sk].
      Parameters:
      wordList - Word List
      beginWord - Beginning Word
      endWord - End Word
      Returns:
      The Transformation Sequence
    • InPlaceWordReversion

      public static final java.lang.String InPlaceWordReversion​(java.lang.String s)
      Given an input string, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in the input will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that the input may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.
      Parameters:
      s - Input String
      Returns:
      Sting with Reversed Words
    • WildcardPatternMatchingValidation

      public static final boolean WildcardPatternMatchingValidation​(java.lang.String s, java.lang.String p)
      Validate the Wild-card Pattern Match
      Parameters:
      s - String
      p - Pattern
      Returns:
      TRUE - Wild-card Pattern Match is Successful
    • ToString

      public static final java.lang.String ToString​(boolean flag)
      Convert the Boolean Flag to String
      Parameters:
      flag - Boolean Flag
      Returns:
      String Value
    • main

      public static final void main​(java.lang.String[] argumentArray)
      Entry Point
      Parameters:
      argumentArray - Argument Array