Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created June 27, 2016 13:22
Show Gist options
  • Save developer-sdk/fc6c442622e170f6b84d572bf8dce21d to your computer and use it in GitHub Desktop.
Save developer-sdk/fc6c442622e170f6b84d572bf8dce21d to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Koi_Align {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = in.nextInt();
}
in.close();
// 테스트용 데이
// int[] array = { 5, 2, 4, 1, 3 };
// int[] array = { 5, 2, 3, 4, 7, 1, 6 };
int maxSequence = 0;
int[] sequence = new int[array.length + 1];
sequence[array[0]] = 1;
for (int i = 1; i < array.length; i++) {
int pivot = array[i];
sequence[pivot] = sequence[pivot - 1] + 1;
maxSequence = Math.max(maxSequence, sequence[pivot - 1] + 1);
}
System.out.println(array.length - maxSequence);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment