package cokr.xit.problems;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

class Solution {


    @Test
    public void main(){
        int[] progresses =  new int[0];
        int[] speeds = new int[0];


        progresses = new int[]{93,30,55};
        speeds = new int[]{1,30,5};
        solution(progresses, speeds);


        progresses = new int[]{95,91,95,95, 1};
        speeds = new int[]{4,2,3,4,20};
        solution(progresses, speeds);

    }

    public int[] solution(int[] progresses, int[] speeds) {
        int[] answer = {};


        int[] endDays = new int[progresses.length];
        List<Integer> releases = new ArrayList<>();
        for(int i=0; i<progresses.length; i++){
            int day = (100-progresses[i])/speeds[i];
            day += (100-progresses[i])%speeds[i]>0?1:0;
            endDays[i] = day;
        }

        check(releases, endDays, endDays[0], 1, 1, false);
        answer = releases.stream().mapToInt(value -> value).toArray();

        return answer;
    }


    private void check(List<Integer> release, int[] endDays, int endDay, int idx, int cnt, boolean isRangeEnd){
        if(isRangeEnd){
            release.add(cnt);
            cnt = 1;
        }
        if(endDays.length == idx){
            release.add(cnt);
            return;
        }

        if(endDays[idx] <= endDay){
            check(release, endDays, endDay, ++idx, ++cnt, false);
        }else{
            check(release, endDays, endDays[idx], ++idx, cnt, true);
        }

    }
}