- #1
bc030400412
- 9
- 0
Q1. Write a function that accepts an array of integers and returns the second largest integer in the array. Return -1 if there is no second largest.
The signature of the function is
public class ID
{
public static void main(String[] args){ }
int f(int[ ] a) { }
}
Examples:
if the input array is {1, 2, 3, 4} then return 3
if the input array is {{4, 1, 2, 3}} then return 3
if the input array is {1, 1, 2, 2} then return 1
if the input array is {1, 1} then return -1
if the input array is {1} then return -1
if the input array is {} then return -1
The signature of the function is
public class ID
{
public static void main(String[] args){ }
int f(int[ ] a) { }
}
Examples:
if the input array is {1, 2, 3, 4} then return 3
if the input array is {{4, 1, 2, 3}} then return 3
if the input array is {1, 1, 2, 2} then return 1
if the input array is {1, 1} then return -1
if the input array is {1} then return -1
if the input array is {} then return -1
Last edited: