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 = 4;
int kth = a[k - 1];

What is the 4th smallest?

  • A

    4

  • B

    1

  • C

    2

  • D

    3

    check_circle

Explanation

Sorted: {1,1,2,3,4,5,6,9}; index 3 holds 3.

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

Related questions