Skip to content

Instantly share code, notes, and snippets.

@abhishek-Kumar009
Created May 31, 2018 21:57
Show Gist options
  • Save abhishek-Kumar009/23da9f2a3c0a57ec58b2d6344332b19e to your computer and use it in GitHub Desktop.
Save abhishek-Kumar009/23da9f2a3c0a57ec58b2d6344332b19e to your computer and use it in GitHub Desktop.
Uncle Johny problem of codeChef
import java.util.Scanner;
public class uncleJohny {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt(); // Number of test Cases
int i, j, l;
for (i = 1; i <= T; i++) {
int N = sc.nextInt();
int[] arr = new int[N + 1];
arr[0] = 0;
for (j = 1; j <= N; j++) { // Loop for taking input of Length of the songs
arr[j] = sc.nextInt();
}
int k = sc.nextInt(); // index of Uncle John before sorting
int comp = arr[k];
for (j = 1; j <= N; j++) {
int min = j;
for (l = j + 1; l <= N; l++) {
if (arr[l] < arr[min])
min = l;
}
int temp = arr[min];
arr[min] = arr[j];
arr[j] = temp;
}
for (j = 1; j <= N; j++) {
if(arr[j] == comp)
System.out.print(j);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment