Package org.drip.service.common
Class RecursionUtil
java.lang.Object
org.drip.service.common.RecursionUtil
public class RecursionUtil
extends java.lang.Object
RecursionUtil implements Recursion Utility Functions.
- Module = Computational Core Module
- Library = Numerical Analysis Library
- Project = Environment, Product/Definition Containers, and Scenario/State Manipulation APIs
- Package = Assorted Data Structures Support Utilities
- Author:
- Lakshmi Krishnamurthy
-
Constructor Summary
Constructors Constructor Description RecursionUtil()
-
Method Summary
Modifier and Type Method Description static boolean
CanPartitionKSubsets(int[] numberArray, int partitionCount)
Given an array of integers and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.static java.util.Set<java.lang.String>
GenerateParenthesis(int n)
Generate the Set of n Parenthesisstatic int
KthGrammar(int n, int k)
On the first row, we write a 0.static int
LongestUncommonSubsequenceLength(java.lang.String[] stringArray)
Given a list of strings, you need to find the longest uncommon subsequence among them.static void
main(java.lang.String[] argumentArray)
Entry Pointstatic java.util.List<java.lang.String>
PhoneCharList(int[] phoneNumber)
Generate all the Words corresponding to the Specified Digitsstatic java.util.List<java.lang.String>
RestoreIPAddresses(java.lang.String s)
Restore the IP Address in the Stringstatic int
ShortestPathSize(int[][] maze)
Calculate the Size of the Shortest Path through the Mazestatic java.util.List<java.lang.Integer>
SmallestPerfectSquareSet(int number)
Generate the List of Smallest Perfect Squares that add to the given Numberstatic java.util.List<java.lang.String>
SubSequenceList(java.lang.String s)
Generate the Set of Sub-sequence Stringsstatic int
WordLadderLength(java.lang.String beginWord, java.lang.String endWord, java.util.Set<java.lang.String> wordSet)
Calculate the smallest Number of changes needed to make the begin word to the end using the Words in the DictionaryMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
RecursionUtil
public RecursionUtil()
-
-
Method Details
-
KthGrammar
public static final int KthGrammar(int n, int k)On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-indexed.)- Parameters:
n
- Nk
- K- Returns:
- The Kth Grammar Integer
-
SubSequenceList
public static final java.util.List<java.lang.String> SubSequenceList(java.lang.String s)Generate the Set of Sub-sequence Strings- Parameters:
s
- Input String- Returns:
- The Set of Sub-sequence Strings
-
LongestUncommonSubsequenceLength
public static final int LongestUncommonSubsequenceLength(java.lang.String[] stringArray)Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string. The input will be a list of strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.- Parameters:
stringArray
- Input String Array- Returns:
- Length of the Longest Uncommon Sub-sequence Length
-
PhoneCharList
public static final java.util.List<java.lang.String> PhoneCharList(int[] phoneNumber)Generate all the Words corresponding to the Specified Digits- Parameters:
phoneNumber
- The Digits of Phone Number- Returns:
- Words corresponding to the Specified Digits
-
CanPartitionKSubsets
public static final boolean CanPartitionKSubsets(int[] numberArray, int partitionCount)Given an array of integers and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.- Parameters:
numberArray
- The Number ArraypartitionCount
- The Partition Count- Returns:
- TRUE - It is possible to divide this array into k non-empty subsets whose sums are all equal.
-
GenerateParenthesis
public static final java.util.Set<java.lang.String> GenerateParenthesis(int n)Generate the Set of n Parenthesis- Parameters:
n
- n- Returns:
- The Set of n Parenthesis
-
ShortestPathSize
public static final int ShortestPathSize(int[][] maze)Calculate the Size of the Shortest Path through the Maze- Parameters:
maze
- The Maze- Returns:
- Size of the Shortest Path through the Maze
-
RestoreIPAddresses
public static final java.util.List<java.lang.String> RestoreIPAddresses(java.lang.String s)Restore the IP Address in the String- Parameters:
s
- The String- Returns:
- IP Address in the String
-
WordLadderLength
public static final int WordLadderLength(java.lang.String beginWord, java.lang.String endWord, java.util.Set<java.lang.String> wordSet)Calculate the smallest Number of changes needed to make the begin word to the end using the Words in the Dictionary- Parameters:
beginWord
- The Begin WordendWord
- The End WordwordSet
- Dictionary- Returns:
- Smallest Number of changes needed
-
SmallestPerfectSquareSet
public static final java.util.List<java.lang.Integer> SmallestPerfectSquareSet(int number)Generate the List of Smallest Perfect Squares that add to the given Number- Parameters:
number
- The Number- Returns:
- The List of Smallest Perfect Squares that add to the given Number
-
main
public static final void main(java.lang.String[] argumentArray) throws java.lang.ExceptionEntry Point- Parameters:
argumentArray
- Array of Arguments- Throws:
java.lang.Exception
- The Exception encountered
-