Advertisement
Spocoman

04. Last K Numbers Sequance

Feb 6th, 2022
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lastKNumbersSequence(n, k) {
  2.  
  3.     let arr = new Array(k + n - 1).fill(0);
  4.     arr[k - 1] = 1;
  5.     for (let i = k; i < n + k - 1; i++){
  6.         for (let j = i - k; j < i; j++){
  7.             arr[i] += arr[j];
  8.         }
  9.     }
  10.     arr.splice(0, k - 1);
  11.     console.log(arr.join(' '));
  12. }
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement