The Fibonacci sequence is defined using the following recursive formula:
F(0) = 0 F(1) = 1 F(M) = F(M - 1) + F(M - 2) if M >= 2A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jump over any distance F(K), where F(K) is the K-th Fibonacci number. Luckily, there are many leaves on the river, and the frog can jump between the leaves, but only in the direction of the bank at position N.
The leaves on the river are represented in an array A consisting of N integers. Consecutive elements of array A represent consecutive positions from 0 to N − 1 on the river. Array A contains only 0s and/or 1s:
- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.
The goal is to count the minimum number of jumps in which the frog can get to the other side of the river (from position −1 to position N). The frog can jump between positions −1 and N (the banks of the river) and every position containing a leaf.
For example, consider array A such that:
A[0] = 0 A[1] = 0 A[2] = 0 A[3] = 1 A[4] = 1 A[5] = 0 A[6] = 1 A[7] = 0 A[8] = 0 A[9] = 0 A[10] = 0The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A consisting of N integers, returns the minimum number of jumps by which the frog can get to the other side of the river. If the frog cannot reach the other side of the river, the function should return −1.
For example, given:
A[0] = 0 A[1] = 0 A[2] = 0 A[3] = 1 A[4] = 1 A[5] = 0 A[6] = 1 A[7] = 0 A[8] = 0 A[9] = 0 A[10] = 0the function should return 3, as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if ()
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if ()
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} els e{
fibonacciMap.put(num, getFibonacciData)
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} els e{
fibonacciMap.put(num, getFibonacciData(num - 1) + getFibonacciData(num - 2))
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} els e{
fibonacciMap.put(num, getFibonacciData(num - 2) + getFibonacciData(num - 1));
return fibonacciMap.get(num);
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, getFibonacciData(num - 2) + getFibonacciData(num - 1));
return fibonacciMap.get(num);
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
// write your code in Java SE 8
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= )
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList)
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Queue;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
int position;
int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return th
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
queu.add(new Point(-1, 0)); // Str
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibo)
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if ()
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next]
}
}
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next]
}
}
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
Point point new Point(next, currentPoint.jump + 1);
queue.add(point);
}
}
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jum + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
Solution.java:27: error: cannot find symbol queu.add(new Point(-1, 0)); // Starting point. ^ symbol: variable queu location: class Solution Solution.java:32: error: position has private access in Point int next = currentPoint.position + fibonacci; ^ Solution.java:34: error: cannot find symbol return currentPoint.jum + 1; ^ symbol: variable jum location: variable currentPoint of type Point Solution.java:38: error: jump has private access in Point queue.add(new Point(next, currentPoint.jump + 1)); ^ Solution.java:62: error: cannot find symbol this.jum = jump; ^ symbol: variable jum 5 errors
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jum) {
this.position = position;
this.jum = jump;
}
}
Solution.java:27: error: cannot find symbol queu.add(new Point(-1, 0)); // Starting point. ^ symbol: variable queu location: class Solution Solution.java:32: error: position has private access in Point int next = currentPoint.position + fibonacci; ^ Solution.java:34: error: jump has private access in Point return currentPoint.jump + 1; ^ Solution.java:38: error: jump has private access in Point queue.add(new Point(next, currentPoint.jump + 1)); ^ Solution.java:63: error: cannot find symbol this.jum = jump; ^ symbol: variable jum 5 errors
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
}
Solution.java:27: error: cannot find symbol queu.add(new Point(-1, 0)); // Starting point. ^ symbol: variable queu location: class Solution Solution.java:32: error: position has private access in Point int next = currentPoint.position + fibonacci; ^ Solution.java:34: error: jump has private access in Point return currentPoint.jump + 1; ^ Solution.java:38: error: jump has private access in Point queue.add(new Point(next, currentPoint.jump + 1)); ^ 4 errors
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.jump + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return th
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.position + fibonacci;
if (next == A.length) {
return currentPoint.jump + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.getJump() + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queu.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.getPosition() + fibonacci;
if (next == A.length) {
return currentPoint.getJump() + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.getJump() + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
Solution.java:27: error: cannot find symbol queu.add(new Point(-1, 0)); // Starting point. ^ symbol: variable queu location: class Solution 1 error
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queue.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.getPosition() + fibonacci;
if (next == A.length) {
return currentPoint.getJump() + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.getJump() + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queue.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.getPosition() + fibonacci;
if (next == A.length) {
return currentPoint.getJump() + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.getJump() + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.LinkedList;
class Solution {
private final Map<Integer, Integer> fibonacciMap = new HashMap<>();
public int solution(int[] A) {
for (int idx =0; getFibonacciData(idx) <= A.length + 1; idx++) {
getFibonacciData(idx);
}
List<Integer> fibonacciList = new ArrayList<>(fibonacciMap.values());
Collections.reverse(fibonacciList);
Queue<Point> queue = new LinkedList<>();
boolean[] check = new boolean[A.length + 1];
queue.add(new Point(-1, 0)); // Starting point.
while (!queue.isEmpty()) {
Point currentPoint = queue.poll();
for (int fibonacci : fibonacciList) {
int next = currentPoint.getPosition() + fibonacci;
if (next == A.length) {
return currentPoint.getJump() + 1;
} else if (next < A.length && next >= 0) {
if (A[next] == 1 && !check[next]) {
check[next] = true;
queue.add(new Point(next, currentPoint.getJump() + 1));
}
}
}
}
return -1;
}
private int getFibonacciData(int num) {
if (num <= 1) {
return num;
}
if (fibonacciMap.containsKey(num)) {
return fibonacciMap.get(num);
} else {
int temp = getFibonacciData(num - 2) + getFibonacciData(num - 1);
fibonacciMap.put(num, temp);
return temp;
}
}
}
class Point {
private int position;
private int jump;
public Point(int position, int jump) {
this.position = position;
this.jump = jump;
}
public int getPosition() {
return this.position;
}
public int getJump() {
return this.jump;
}
}
The solution obtained perfect score.