Developing Algorithms Using ArrayLists

AP Computer Science A· difficulty 3/5

int[] a = {3, 1, 4, 1, 5, 9, 2, 6};
java.util.Arrays.sort(a);
int k = 3;
int kth = a[a.length - k];

What is the 3rd largest element?

  • A

    5

    check_circle
  • B

    6

  • C

    9

  • D

    4

Explanation

Sorted: {1,1,2,3,4,5,6,9}; the 3rd largest is 5.

Want 10 more like this — adaptive to your weak spots?

Related questions