Last active
September 19, 2017 08:49
-
-
Save caub/d7f326aeea492189aa0b14ba36478e8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2 globals defined at boot of nodejs engine | |
rl = cb => require('readline').createInterface({input:process.stdin}).on('line',cb); | |
print = console.log; | |
/* | |
Let's call an integer "repetitive" if it contains two of the same digit in a row. For example, 12232 is repetitive but 1232 is not. | |
Given a positive integer n < 10^15, return the number of nonrepetitive integers in [1..n]. | |
*/ | |
// prog | |
rl(s=>{r=0;d=s.length-1;for(i=0;i<=d;i++){r+=(i>0&&s[i-1]<s[i]?s[i]-1:s[i])*9**(d-i);if(s[i-1]==s[i]){r--;break}}for(i=0;i<d;i++)r+=9**i;print(r)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment