DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Ilya Nevolin
Ilya Nevolin

Posted on

3 new hard challenges

I've added 3 hard challenges to codr's ranked mode. Two are related to important algorithms, below is the third related to cryptography. Visit codr for more https://nevolin.be/codr/

Can you solve it?

function numDecodings(s) {
  if (s == null || s.length == 0) {
    return 0;
  }
  const dp = Array(s.length + 1).fill(0);
  dp[0] = 1;
  dp[1] = s[0] !== "0" ? 1 : 0;
  for (let i = 2; i < s.length + 1; i++) {
     const one = +s.slice(i - 1, i);
     const two = +s.slice(i - 2, i);
    if (two >= 10 && two <= 26) {
      dp[i] = dp[i - 2];
    }
    if (one >= 1 && one <= 9) {
      dp[i] += dp[i - 1];
    }
  }
  return dp[dp.length - 1];
}

let A = numDecodings('5646');
// A = ?
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
sreeragsprks profile image
Sreeragsprks

A=1

Visualizing Promises and Async/Await 🀯

async await

☝️ Check out this all-time classic DEV post