Answered step by step
Verified Expert Solution
Link Copied!

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 "tree_id count info_type". Values are separated by a single space.
The tree_id and count are made of of digits, that are at most 9 digits long and start as non-zero 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.
info_type will be either "used_ornaments" or "max_capacity". Hence For each tree, depending on info_type 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 tree_ids of Christmas trees which has less space than newOrnamentsToAdd count. Return their ids in an array sorted increasingly.
Example
n =7
data =["3099 used_ornaments", "30105 max_capacity", "12100 used_ornaments", "2080 used_ornaments", "12120 max_capacity", "20101 max_capacity", "21110 used_ornaments"] roAdd=20
ID Used Max Cap. RemainingSpace
30991056
1210012020
208010112
21110
The trees with id's 30 and 12 cannot be decorated further for more than newOrnaments ToAdd =20 ornaments. In sorted numerical order, the return array is ["12","30"].
Function Description
Complete the function processChristmas Trees in the editor below in java.
The function has the following parameter(s):
string data[n]: each data[i] 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:
1<= n, newOrnamentsToAdd <=10^5
1<= newOrnamentsToAdds n
Each tree_id contains only characters in the range ascii['0'-'9'], is at most 9 digits long and starts with a non-zero digit.
Each count contains only characters in the range ascii['0'-'9'] and begins with a non-zero digit
0< count <=10
Each info_type is either "used_ornaments" or "max_capacity".
Each tree_id's used_ornaments count < max_capacity 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 STRING_ARRAY.
*The function accepts following parameters:
1. STRING_ARRAY data
2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions