generated from nighthawkcoders/student_2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
2023 FRQ:
A.
public void cleanData(double lower, double upper) {
// iterator to safely remove elements from the ArrayList
Iterator<Double> iterator = temperatures.iterator();
while (iterator.hasNext()) {
double temp = iterator.next();
if (temp < lower || temp > upper) {
iterator.remove();
}
}
}
Iterates and compares each value to the upper and lower.
B.
public int longestHeatWave(double threshold) {
int maxHeatWaveLength = 0; // The longest heatwave length
int currentHeatWaveLength = 0; // The current heatwave length
for (double temp : temperatures) {
if (temp > threshold) {
currentHeatWaveLength++;
maxHeatWaveLength = Math.max(maxHeatWaveLength, currentHeatWaveLength);
} else {
currentHeatWaveLength = 0; // Reset if temperature drops below threshold
}
}
return maxHeatWaveLength;
}
Iterates and updates length of streak, udates max if longer is found
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels