Monday, 13 November 2023

// Program to convert recursive fibonacci into dp by tabulation method(bottom-up)

// tc= O(n)

// sc= O(1) = extra array space is also removed


import java.util.*;

public class dp {

    public static void main(String[] args) {

       int n = 5;

       //int dp[] = new int[n+1];

       int prev2 = 0;

       int prev = 1;

       System.out.println(prev2);

       System.out.println(prev);

       for(int i = 2; i<n+1;i++)

       {

         int curr = prev + prev2;

         System.out.println(curr);

         prev2 = prev;

         prev = curr;

       }

       //System.out.println(prev);

    }

}


No comments:

Post a Comment

Good thoughtful question on Binary search on answers

Problem link:  https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...