Algorithm
Level 0
181921

181921

Link

https://school.programmers.co.kr/learn/courses/30/lessons/181921 (opens in a new tab)

Answer

JavaScript

function* gen50() {
  let i = 1;
 
  while (true) {
    yield Number(Number(i).toString(2)) * 5;
    i++;
  }
}
 
function solution(l, r) {
  const n = gen50();
  let a = 0;
  const arr = [];
 
  while (a < l) {
    a = n.next().value;
  }
  while (a <= r) {
    arr.push(a);
    a = n.next().value;
  }
 
  return arr.length ? arr : [-1];
}
function solution(l, r) {
  const result = Array.from({ length: r - l + 1 }, (_, i) => i + l).filter(
    (n) => !/[^05]/.test(n)
  );
  return result.length ? result : [-1];
}