You are on page 1of 8

{\\\}

1) AccessLevel
Problem Statement
In many computer systems and networks, different users are granted different levels of
access to different resources. In this case, you are given a int[] rights, indicating the
privilege level of each user to use some system resource. You are also given a int
minPermission, which is the minimum permission a user must have to use this resource.
You are to return a String indicating which users can and cannot access this resource.
Each character in the return value corresponds to the element of users with the same
index. 'A' indicates the user is allowed access, while 'D' indicates the user is denied
access.
Definition
Class: AccessLevel
Method: canAccess
Parameters: int[], int
Returns: String
Method signature: String canAccess(int[] rights, int minPermission)
(be sure your method is public)
Notes
- If users is empty, then a zero-length String ("") should be returned.
Constraints
- users will contain between 0 and 50 elements, inclusive.
- Each element of users will be between 0 and 100, inclusive.
- minPermission will be between 0 and 100, inclusive.
Examples
0)
{0,1,2,3,4,5}
2
Returns: "DDAAAA"
Here, the first two users don't have sufficient privileges, but the remainder do.
1)
{5,3,2,10,0}
20
Returns: "DDDDD"
Unfortunately, nobody has sufficient access.
2)
{}
20
Returns: ""
It makes no difference what permission is required, since there are no users to check.

3)

{34,78,9,52,11,1}
49
Returns: "DADADD"
2) AccountBalance
Problem Statement
You are working for the financial institution TopBank, and you have been tasked with
writing a module that will take an initial account balance, along with a list of that day's
transactions, and return the ending balance for the day.
Each transaction will be either a credit, which adds funds to the account, or a debit, which
removes funds from the account. If a debit exceeds the available funds at the time, then
the account balance will go negative. You will be given an int startingBalance, the initial
account balance. You will also be given a String[] transactions, the list of transactions for
the day. Each element of transactions will be in the form "type amount" (quotes added for
clarity). Each type will be 'C' or 'D', for credit or debit, respectively. Each amount will be
an integer between 1 and 1000000, inclusive, with no leading zeros. You are to return an
int representing the ending balance after processing all of the transactions.
Definition
Class: AccountBalance
Method: processTransactions
Parameters: int, String[]
Returns: int
Method signature: int processTransactions(int startingBalance, String[] transactions)
(be sure your method is public)
Constraints
- startingBalance will be between 0 and 1000000, inclusive.
- transactions will have between 0 and 50 elements, inclusive.
- Each element of transactions will be formatted as "type amount" (quotes added for
clarity).
- Each type will be 'C' or 'D'.
- Each amount will represent an integer between 1 and 1000000, inclusive, with no
leading zeros.
Examples
0)
100
{"C 1000", "D 500", "D 350"}
Returns: 250
This person had 100 dollars, got their paycheck, then went shopping at two different
stores. 100 + 1000 - 500 - 350 = 250.

1)
100

{}
Returns: 100
With no transactions, the balance doesn't change by the end of the day.
2)
100
{"D 50", "D 20", "D 40"}
Returns: -10
Uh oh! This person's account is overdrawn.
3)
53874
{"D 1234", "C 987", "D 2345", "C 654", "D 6789", "D 34567"}
Returns: 10580
Several transactions of both types.
3) AcidRain
Problem Statement
You are a farmer living in a 2-dimensional world. Your crops look like an infinite line
parallel to the x-axis, with the y-coordinate equal to 0. According to the weather forecast,
the next rain will be acid, and therefore very harmful to your plants. The rain consists of
an infinite number of drops that fall down vertically (parallel to the y-axis). For every x,
where x is an arbitrary number (not necessarily an integer), a drop will fall toward the
point (x, 0).
To protect your crops, you have built some shields above the ground. Each shield is a line
segment parallel to the x-axis, with negligible thickness. If a drop of rain falls on a shield,
it will flow to the closest end of the shield and continue falling straight down vertically
from that point. If a drop falls exactly in the middle of a shield, the drop will divide into
two equal parts that flow to opposite ends of the shield and continue falling from there. If
two or more shields have common endpoints they will act as one combined shield. See
examples for clarification.
The locations of your existing shields will be given in the three int[]s b, e and y. The
endpoints of the i-th shield are located at (b[i], y[i]) and (e[i], y[i]). Define B as the
minimum value in b, and E as the maximum value in e. Your task is to build enough
additional shields to protect all the crops between (B, 0) and (E, 0), exclusive (that is, all
crops whose x-coordinates lie in the open interval (B, E) ). Each shield must be a line
segment parallel to the x-axis with non-zero length and a positive y-coordinate. Each
shield you build must have integer endpoints and a positive length. Build these new
shields in such a way that the sum of their lengths is minimized. Return the sum of the
new shields' lengths.
Definition
Class: AcidRain
Method: saveHarvest
Parameters: int[], int[], int[]
Returns: int

Method signature: int saveHarvest(int[] b, int[] e, int[] y)


(be sure your method is public)
Constraints
- b will contain between 1 and 25 elements, inclusive.
- b, e and y will contain the same number of elements.
- Each element of b will be between 0 and 10, inclusive.
- Each element of e will be between 0 and 10, inclusive.
- For all i, the i-th element of b will be less than the i-th element of e.
- Each element of y will be between 1 and 100000, inclusive.
- No two shields will overlap, but they can have common endpoints.
Examples
0)
{1}
{2}
{1}
Returns: 0
The method should return 0 because all harvest in the interval (1, 2) is already safe.
1)
{1, 2}
{2, 3}
{1, 1}
Returns: 0
These two shields go from (1, 1) to (2, 1) and (2, 1) to (3, 1). Since they share a common
endpoint, they act as one combined shield. No additional shields need to be built since all
harvest in the interval (1, 3) is safe.
2)
{0,1}
{1, 3}
{100, 100}
Returns: 0
3)
{0,1}
{2,4}
{1,2}
Returns: 1
4)
{1, 0, 3, 5}
{4, 3, 5, 6}
{10, 3, 1000, 8}
Returns: 2

4) Acronyms
Problem Statement

Acronyms are commonly used to make documents more concise. Your task in this
problem is to develop a program that automates the conversion of sequences of words
into acronyms in a String[], document. A sequence of words must meet all of the
following criteria before it can be converted to an acronym:
The words in the sequence must all be within one sentence.
The sequence must not include the first word in a sentence.
At least two words in the sequence must begin with uppercase letters.
The first and last words in the sequence must begin with uppercase letters.
There may not be two adjacent words that do not begin with uppercase letters in the
sequence.
The sequence must be as long as possible. It may not be a subsequence of any longer
sequence meeting the five criteria above.
A word is defined as a sequence of characters surrounded on both sides by spaces or
edges of the element of document. Note that a word may include non-letter characters. A
new sentence, in this problem, always starts at the beginning of the input and after two
consecutive spaces, where a new line (new element of document) counts as one space.
For each sequence of words meeting the criteria as defined above, you should convert it
to an acronym by replacing the whole sequence of words with all the uppercase letters in
the words that start with uppercase letters (in order). The only caveat to this is that if there
are non-letter characters at the end of the last word in the sequence, you should not
replace them.
For example, "TopCoder, Inc." would become "TCI.". Note that the '.' at the end of "Inc."
remains in the acronym but the ',' at the end of "TopCoder," is removed. Also, "United
States of America" would be converted to "USA"; there is no 'o' because "of" does not
start with an uppercase letter.
After inserting the acronyms, you should return a String representing the entire
document. A new line in the input always counts as one space, and this should be
represented in the output.
Definition
Class: Acronyms
Method: acronize
Parameters: String[]
Returns: String
Method signature: String acronize(String[] document)
(be sure your method is public)
Notes
- Since new lines count as spaces, the input is identical in function to a single String that
is the concatenation of all the elements of document with single spaces inserted between
them.
Constraints
- document will contain between 1 and 50 elements, inclusive.

- Each element of document will contain between 1 and 50 characters, inclusive.


- Each character in document will have ASCII values between 32 and 122 inclusive.
- No element of document will have leading spaces.
- No element of document will have more than one trailing space.
- The last element of document will not have trailing spaces.
- There will not be two adjacent non-letter characters other than spaces.
- There will never be more than 2 consecutive spaces in document
Examples
0)
{"We the people of the United States of America."}
Returns: "We the people of the USA."
"of" is not include in the acronym since it starts with a lowercase letter.
1)
{"Don't","worry.","Be","Happy!"}
Returns: "Don't worry. BH!"
Even though there is a period, there is only one sentence according to the rules of this
problem.
2)
{"Entering contests at TopCoder, Inc.", "is a good way to develop your skills."}
Returns: "Entering contests at TCI. is a good way to develop your skills."
Be sure to include the period after "TCI" in your return.
3)
{"Working at the United States Postal Service",
"in the United States of America",
"is a satisfying experience."}
Returns: "Working at the USPS in the USA is a satisfying experience."
4)
{"a A & a & a B"}
Returns: "a A & a & a B"
5)
{"The First word can't be included. In","A sequence, that is."}
Returns: "The First word can't be included. In A sequence, that is."
"The" and "In" are both the first words in sentences.
6)
{"A Test & Test & & TEst"}
Returns: "A TT & & TEst"
Note that "&" counts as a word.
7)
{"This is a TEST tEST Test. ", ".Go Test"}
Returns: "This is a TESTT. .Go Test"

5) ActivateGame
Problem Statement

ActivateGame is played on a rectangular grid with N rows and M columns. The rows are
numbered 0 to N-1 from top to bottom, and the columns are numbered 0 to M-1 from left
to right. A number is assigned to each cell.
The game is played as follows. Initially, only the top-left cell (row 0, column 0) is
activated, and your score is zero. Then, on each turn, you choose one activated cell and
one non-activated cell which is vertically or horizontally adjacent to that cell. The
absolute difference between the numbers assigned to those two cells is added to your
score, and the non-activated cell becomes activated. This is repeated until all the cells
have been activated.
You are given a String[] grid. The j-th character of the i-th element of grid represents the
number assigned to the cell at row i, column j. Characters are mapped to numbers as
follows:
'0' - '9' corresponds to 0 - 9
'a' - 'z' corresponds to 10 - 35
'A' - 'Z' corresponds to 36 - 61
Return the maximum possible score you can achieve.
Definition
Class: ActivateGame
Method: findMaxScore
Parameters: String[]
Returns: int
Method signature: int findMaxScore(String[] grid)
(be sure your method is public)
Constraints
- grid will contain between 1 and 50 elements, inclusive.
- Each element of grid will contain between 1 and 50 characters, inclusive.
- Each element of grid will contain the same number of characters.
- grid will contain at least two characters.
- Each character in grid will be '0'-'9', 'a'-'z', or 'A'-'Z'.
Examples
0)
{"05",
"aB"}
Returns: 69
Initially only the cell containing '0' is activated. Use the following sequence of moves to
maximize your score:
Choose the activated cell containing '0' and the adjacent non-activated cell containing 'a'
(which represents the number 10). Their absolute difference, 10, is added to your score,
and the cell containing 'a' becomes activated.
Choose the activated cell containing 'a' and the adjacent non-activated cell containing 'B'
(which represents the number 37). Their absolute difference is 27.
Choose the activated cell containing 'B' and the adjacent non-activated cell containing '5'
(which represents the number 5). Their absolute difference is 32.
Your total score is 10 + 27 + 32 = 69.

1)
{"03",
"21"}
Returns: 7
One possible solution is to choose cells in the following order:
0 and 3
0 and 2
3 and 1
2)
{"John",
"Brus",
"Gogo"}
Returns: 118
3)
{"AAA",
"AAA",
"AAA"}
Returns: 0

You might also like