Leetcode 2923. Find Champion I
You are given an array of integers where each integer represents the points a player scored in a game. You need to identify the player who scored the maximum points and return that value. If there are multiple players with the same maximum points, return any one of them.
public class FindChampion {
public static int findChampion(int[] scores) {
// Initial assumption that the maximum score is the first element
int maxPoints = scores[0];
// Loop through the array starting from the second element
for (int i = 1; i < scores.length; i++) {
if (scores[i] > maxPoints) {
maxPoints = scores[i];
}
}
// Return the maximum points
return maxPoints;
}
public static void main(String[] args) {
// Example test case
int[] scores = {10, 20, 30, 20, 30, 10};
System.out.println("Champion's Score: " + findChampion(scores)); // Output: 30
}
}
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?