Picking Numbers Hackerrank Solution - java
Code::
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Solution {
public static void main(String[] args) throws IOException {
int[] arr = new int[100];
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
for(int i=0;i<n;i++){
int num = scn.nextInt();
arr[num]++;
}
int max = 0;
for(int i=0;i<99;i++){
max = Math.max(max,arr[i]+arr[i+1]);
}
System.out.println(max);
}
}
Comments
Post a Comment