Problem Statement
You are given a list of integer intervals, ranges, where each interval is specified by a
Your task is to find the largest integer that is in at least one of the intervals and is a perfect cube. Return this integer in a
For example {"1-1000000000001"} would return "1000000000000" which is 100003.
Definition
- Class:
- BigCube
- Method:
- largestCube
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String largestCube(String[] range)
- (be sure your method is public)
Notes
- C++ users: the 64 bit integer type is long long.
Constraints
- range will have between 1 and 50 elements inclusive.
- Each element of range will contain between 3 and 31 characters inclusive.
- Each element of range will be of the form "
- " where and are separated by exactly one hyphen, '-'. - Each character of
and will be a digit between '0' and '9' inclusive. and will contain no leading zeros. and will be between 0 and 1000000000000000 (1e15) inclusive. will be less than or equal to
Examples
{"1-1000000000001"}
Returns: "1000000000000"
The example from above: 100003
{"10-999999999999990","11-999999999999991","12-999999999999992", "13-999999999999993","14-999999999999994","15-999999999999995", "16-999999999999996","17-999999999999993","18-999999999999994", "19-999999999999999"}
Returns: "999970000299999"
999993
{"0-3","10-20","30-60","80-120"}
Returns: "1"
{"0-0","2-7","9-26","28-63","65-124"}
Returns: "0"
{"999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972"}
Returns: ""
{"0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000", "0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000","0-1000000000000" }
Returns: "1000000000000"
{"1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999", "1-999999999999","1-999999999999","1-999999999999","1-999999999999","1-999999999999" }
Returns: "999700029999"
{"999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "1000001-1000000000" }
Returns: "1000000000"
{"999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "999700030000-999999999999","999400119993-999700029998", "999100269974-999400119991","998800479937-999100269972", "0-0" }
Returns: "0"
{"999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999", "999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999","999970000300000-999999999999999" }
Returns: ""
{"0-0","2-2","3-3","4-4","5-5","6-6","7-7","9-9","10-10","12-12", "14-14","16-16","18-18","20-20","22-22","24-24","26-26","28-28", "30-30","32-32","34-34","36-36","38-38","40-40","42-42","44-44", "46-46","48-48","50-50","52-52","54-54","56-56","58-58","60-60", "62-62","65-65","67-67","69-69","71-71","73-73","75-75","77-77", "79-79","81-81","83-83","85-85","87-87","89-89","99-99", "999970000300000-999999999999999" }
Returns: "0"
{"1-8"}
Returns: "8"
{"2-26"}
Returns: "8"
{"2-63"}
Returns: "27"
{"1-2197"}
Returns: "2197"
{"125000000000000-125000000000000"}
Returns: "125000000000000"
{"1881365963625-1881365963625"}
Returns: "1881365963625"
{"123456789012345-234567890123456"}
Returns: "234565479336448"
{"100-100","2-2","3-3","4-4","5-5","6-6","7-7","9-9","10-10","12-12", "14-14","16-16","18-18","20-20","22-22","24-24","26-26","28-28", "30-30","32-32","34-34","36-36","38-38","40-40","42-42","44-44", "46-46","48-48","50-50","52-52","54-54","56-56","58-58","60-60", "62-62","65-65","67-67","69-69","71-71","73-73","75-75","77-77", "79-79","81-81","83-83","85-85","87-87","89-89","99-99", "999970000300000-999999999999999" }
Returns: ""
{"1000000000001-1000333333333"}
Returns: "1000300030001"
{ "1-1000000000001" }
Returns: "1000000000000"
{ "1-1" }
Returns: "1"
{ "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000", "1-1000000000000000" }
Returns: "1000000000000000"
{ "1-1000000000000000" }
Returns: "1000000000000000"
{ "2-4", "120-130" }
Returns: "125"
{ "0-1001", "2-2", "3-3", "4-4", "5-5", "6-6", "7-7", "9-9", "10-10", "12-12", "14-14", "16-16", "18-18", "20-20", "22-22", "24-24", "26-26", "28-28", "30-30", "32-32", "34-34", "36-36", "38-38", "40-40", "42-42", "44-44", "46-46", "48-48", "50-50", "52-52", "54-54", "56-56", "58-58", "60-60", "62-62", "65-65", "67-67", "69-69", "71-71", "73-73", "75-75", "77-77", "79-79", "81-81", "83-83", "85-85", "87-87", "89-89", "99-99", "1-999999999999999" }
Returns: "999970000299999"
{ "99994258523375-99994258523375" }
Returns: "99994258523375"
{ "8-10" }
Returns: "8"
{ "0-0", "2-2", "3-3", "4-4", "5-5", "6-6", "7-7", "9-9", "10-10", "12-12", "14-14", "16-16", "18-18", "20-20", "22-22", "24-24", "26-26", "28-28", "30-30", "32-32", "34-34", "36-36", "38-38", "40-40", "42-42", "44-44", "46-46", "48-48", "50-50", "52-52", "54-54", "56-56", "58-58", "60-60", "62-62", "65-65", "67-67", "69-69", "71-71", "73-73", "75-75", "77-77", "79-79", "81-81", "83-83", "85-85", "87-87", "89-89", "99-99", "999970000300000-999999999999999" }
Returns: "0"
{ "63-100", "998-1001", "1003-998988" }
Returns: "970299"
{ "10-999999999999990", "11-999999999999991", "12-999999999999992", "13-999999999999993", "14-999999999999994", "15-999999999999995", "16-999999999999996", "17-999999999999993", "18-999999999999994", "19-999999999999999" }
Returns: "999970000299999"
{ "3-8" }
Returns: "8"
{ "1-10", "1-9872564", "23457-334676" }
Returns: "9800344"
{ "1000000000000000-1000000000000000" }
Returns: "1000000000000000"