We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functiongetValue(a,xor){if(xor===0){if(a===0)return0;if(a===1)return1;}if(xor==1){if(a===0)return1;if(a===1)return0;}}functioncipher(k,s){// Write your code hereletn=s.length-k+1;letarr=Array(n).fill(-1);arr[0]=parseInt(s[0]);leti=1;letcurrentXor=0;while(i<n){letleft=i-k+1>=0?i-k+1:0;if(left>0){currentXor^=arr[left-1];}currentXor^=arr[i-1];arr[i]=getValue(currentXor,parseInt(s[i]));i++;}returnarr.join('');}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cipher
You are viewing a single comment's thread. Return to all comments →