public class CodeCamp extends Object
Modifier and Type | Method and Description |
---|---|
static int |
getValueOfMostValuablePlot(int[][] city)
Given a 2D array of ints return the value of the
most valuable contiguous sub rectangle in the 2D array.
|
static int |
hammingDistance(int[] aData,
int[] bData)
Determine the Hamming distance between two arrays of ints.
|
static boolean |
isPermutation(int[] aData,
int[] bData)
Determine if one array of ints is a permutation of another.
|
static int |
mostVowels(String[] arrayOfStrings)
Determine the index of the String that
has the largest number of vowels.
|
static boolean |
queensAreSafe(char[][] board)
Determine if the chess board represented by board is a safe set up.
|
static int |
sharedBirthdays(int numPeople,
int numDaysInYear)
Perform an experiment simulating the birthday problem.
|
public static int getValueOfMostValuablePlot(int[][] city)
pre: mat != null, mat.length > 0, mat[0].length > 0, mat is a rectangular matrix.
post: return the value of the most valuable contigous sub rectangle
in city.
city
- The 2D array of ints representing the value of
each block in a portion of a city.public static int hammingDistance(int[] aData, int[] bData)
aData
- != null, aData.length == aData.lengthbData
- != nullpublic static boolean isPermutation(int[] aData, int[] bData)
aData
- != nullbData
- != nullpublic static int mostVowels(String[] arrayOfStrings)
pre: arrayOfStrings != null, arrayOfStrings.length > 0, there is an least 1 non null element in arrayOfStrings.
post: return the index of the non-null element in arrayOfStrings that has the
largest number of characters that are vowels.
If there is a tie return the index closest to zero.
The empty String, "", has zero vowels.
It is possible for the maximum number of vowels to be 0.
arrayOfStrings
- the array to checkpublic static boolean queensAreSafe(char[][] board)
pre: board != null, board.length > 0, board is a square matrix.
(In other words all rows in board have board.length columns.),
all elements of board == 'q' or '.'. 'q's represent queens, '.'s
represent open spaces.
post: return true if the configuration of board is safe,
that is no queen can attack any other queen on the board.
false otherwise.
the parameter board is not altered as a result of
this method.
board
- the chessboardpublic static int sharedBirthdays(int numPeople, int numDaysInYear)
numPeople
- The number of people in the experiment.
This value must be > 0numDaysInYear
- The number of days in the year for this experiment.
This value must be > 0