Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // console.log('this is a debug message');
- function solution(A) {
- A.sort(function (a, b){return a-b;});
- var res = 1;
- var counts = {};
- for (var i = 0; i < A.length; i++) {
- var num = A[i];
- counts[num] = counts[num] ? counts[num] + 1 : 1;
- }
- var ancienV,ancienO,res=1;
- for (var value in counts) {
- var occ = counts[value];
- console.log(value+' '+occ);
- //console.log(ancien[obj])
- res = Math.max(res,occ)
- if((Math.abs(ancienV-value)<=1)){
- res = Math.max(res,Math.abs(occ-ancienO))
- }
- ancienV = value
- ancienO = occ
- }
- //console.log(res)
- return res
- }
- console.log(
- solution(
- [2,5,4,7,8,9,15,2]
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement