티스토리 뷰

Algorithms

Beautiful Days at the Movies

seoca 2020. 10. 18. 18:41

 

Solution in Javascript

const i = 20;
const j = 23;
const k = 6;

function beautifulDays(i, j, k) {

    let beautifulDay = 0;

    while(i<=j){ //'i' is starting day
            //num to String //string to array //reverse //array to string
        let a = i.toString().split('').reverse().join('');
        if((i-a) % k === 0){
            beautifulDay++;
        }
        i++;
    }
    console.log(beautifulDay);
}

beautifulDays(i,j,k); //2

 

 

Reference

www.hackerrank.com/challenges/beautiful-days-at-the-movies/problem

'Algorithms' 카테고리의 다른 글

Viral Advertising  (0) 2020.10.22
Angry Professor  (0) 2020.10.19
Migratory Birds  (0) 2020.10.01
Utopian Tree  (0) 2020.10.01
Electronics Shop  (0) 2020.09.25