Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Christmas Ornaments [ SETUP ] To decorate a typical Christmas tree, we use ornaments. And sometimes, we'd like to decorate even further, if the tree
Christmas Ornaments SETUP
To decorate a typical Christmas tree, we use ornaments. And sometimes, we'd like to decorate even further, if the tree permits us Our condition to decorate further is that, once we use more ornaments, the tree should still have space for at least one more ornament.
A data set is provided as a string array, where each entry is denotes "treeid count infotype". Values are separated by a single space.
The treeid and count are made of of digits, that are at most digits long and start as nonzero digit.
count represents the number of ornaments which could mean the number of existing ornaments on the tree, or the tree's max capacity of ornaments.
infotype will be either "usedornaments" or "maxcapacity". Hence For each tree, depending on infotype you might get information about either number of ornaments used on this tree, or the max capacity of this very same tree.
Remember, we are looking to find out about the Christmas trees which won't permit us using more ornaments.
Given a data set with entries in no particular order, return an array of strings that denote treeids of Christmas trees which has less space than newOrnamentsToAdd count. Return their ids in an array sorted increasingly.
Example
n
data usedornaments", maxcapacity", usedornaments", usedornaments", maxcapacity", maxcapacity", usedornaments" roAdd
ID Used Max Cap. RemainingSpace
The trees with id's and cannot be decorated further for more than newOrnaments ToAdd ornaments. In sorted numerical order, the return array is
Function Description
Complete the function processChristmas Trees in the editor below in java.
The function has the following parameters:
string datan: each datai denotes the ith entry in the data
int newOrnaments ToAdd: the number of new ornaments we'd like to add.
Returns:
string: a string array of tree id's, sorted ascending by numeric value
Constraints:
n newOrnamentsToAdd
newOrnamentsToAdds n
Each treeid contains only characters in the range ascii is at most digits long and starts with a nonzero digit.
Each count contains only characters in the range ascii and begins with a nonzero digit
count
Each infotype is either "usedornaments" or "maxcapacity".
Each treeid's usedornaments count maxcapacity count
Each tree has one decoration session.
The result will contain at least one element.
class Result
Complete the 'processChristmas Trees' function below.
The function is expected to return a STRINGARRAY.
The function accepts following parameters:
STRINGARRAY data
INTEGER newOrnaments ToAdd
public static List processChristmas Trees List data, int newOrnamentsToAdd
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started