I wrote this solution pretty quickly... and then kept having the wrong value.
I went down a rabbit hole involving hexdump and such because I was pretty confident in what the code was supposed to do and didn't see a valid result come up. It drove me crazy, but finally after way more time digging than I'd like to admit, here's my solution:
importFsfrom"fs"importPathfrom"path"constCASE_ASCII_OFFSET=32letinput=Fs.readFileSync(Path.join(__dirname,"input.txt")).toString().trim()for(leti=0;i<input.length;i++){constcurrentValue=input.charAt(i)constnextValue=input.charAt(i+1)// reached the endif(nextValue===undefined){continue}constisSameTypeAndOppositePolarity=Math.abs(currentValue.charCodeAt(0)-nextValue.charCodeAt(0))===CASE_ASCII_OFFSETif(isSameTypeAndOppositePolarity){input=input.slice(0,i)+input.slice(i+2)// Coming back to previous position but since it's going to be// incremented by the for loop, let's take a supplementary stepi=Math.max(-1,i-2)}}console.log(input.length)
I'll try and find some time to write up what problem I encountered
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I wrote this solution pretty quickly... and then kept having the wrong value.
I went down a rabbit hole involving hexdump and such because I was pretty confident in what the code was supposed to do and didn't see a valid result come up. It drove me crazy, but finally after way more time digging than I'd like to admit, here's my solution:
I'll try and find some time to write up what problem I encountered