using
System;
using
System.Collections.Generic;
class
GFG {
static
void
minRemovalsConsecutive(
int
[]a,
int
n)
{
Dictionary<
int
,
bool
> map1 =
new
Dictionary<
int
,
bool
>();
foreach
(
int
val
in
a) {
map1.Add(val,
true
);
}
Dictionary<
int
,
bool
> map2 =
new
Dictionary<
int
,
bool
>();
foreach
(KeyValuePair<
int
,
bool
> k
in
map1){
if
(map1.ContainsKey(k.Key - 1)) {
map2.Add(k.Key,
false
);
}
else
{
map2.Add(k.Key,
true
);
}
}
int
max = 0;
foreach
(KeyValuePair<
int
,
bool
> k
in
map2){
if
(map2.ContainsKey(k.Key)) {
int
t1 = 1;
while
(map2.ContainsKey(k.Key
+ t1)) {
t1++;
}
if
(t1 > max) {
max = t1;
}
}
}
Console.WriteLine(n - max);
}
public
static
void
Main()
{
int
N = 5;
int
[]arr = { 45, 42, 46, 48, 47 };
minRemovalsConsecutive(arr, N);
}
}