
How can I get the
Nth
Fibonacci number withO(n)
time andO(1)
space complexity. 
How to calculate Fibonacci numbers without Recursion or Iteration?
This is the code that I took from here, using Recursion with Memoization in Java
import java.util.*;
public class fibonacci{
public static int fibo(int n){
if(n==1)return values[0];
if(n==2)return values[1];
else{
values[n1]=fibo(n1)+fibo(n2);
return values[n1];
}
}
public static void main(String args[]){
int n;
Scanner sc= new Scanner(System.in);
n=sc.nextInt();
sc.close();
values[0]=0;
values[1]=1;
System.out.println(fibo(n));
}
static int values[]=new int[1000];
}
The question is how can I implement the same without using Recursion.