SHARE
TWEET

Untitled

a guest Mar 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(n, lost, reserve) {
  2.     let arr = new Array(n).fill(1), index=0;
  3.     arr = arr.map((v,i) => {
  4.         if(lost.indexOf(i+1) >= 0 && reserve.indexOf(i+1) >= 0) return 1;
  5.         if(lost.indexOf(i+1) >= 0) return 0;
  6.         if(reserve.indexOf(i+1) >= 0) return 2;
  7.        
  8.         return 1;
  9.     })
  10.     arr.forEach((v,i) => {
  11.         if(arr[i-1] !== undefined && arr[i] === 2 && arr[i-1] === 0){
  12.             arr[i-1]=1; arr[i]=1;
  13.         }
  14.         else if(arr[i+1] !== undefined && arr[i] === 2 && arr[i+1] === 0){
  15.             arr[i+1]=1; arr[i]=1;
  16.         }
  17.     })
  18.     arr.forEach(v => {
  19.         if(v >= 1) index++;
  20.     })
  21.     return index;
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top