Facebook Coding Interview Question — How Many Ways to Decode This Message?

Abhijit chakra
Everything4Coding
Published in
Oct 13, 2020

Facebook coding interview question and answer — how many ways to decode this message? digit -> 0–9 a->1 b-> 2 …..z->26 here i have attached the picture for better understanding

Here i have added the solutions there could be better solution please post if you are solving

function countDecodeDigit(digit,startPoint,totalLength){
var maxDigit = 26

if(digit === 0){
return 0
}
if(digit === “”){
return “”
}
if(startPoint >= totalLength){

return 0
}
if(!digit){
return 0
}
if(parseInt(digit.toString().slice(startPoint,startPoint+2)) < maxDigit){
return 1+ countDecodeDigit(digit.toString(),startPoint+1,totalLength)
}else{
return countDecodeDigit(digit.toString(),startPoint+1,totalLength)
}
}
console.log(“number of ways::”+countDecodeDigit(123,0,4))

The best book for cracking coding interview in my experience , available on amazon, link is here below

https://amzn.to/3cFjyGy

https://amzn.to/3cFjyGy

--

--