Frog one solution
$10-30 USD
货到付款
A small frog wants to get to the other side of a pond. The frog is initially located on one bank of the pond (position 0) and wants to get to the other bank (position X). The frog can jump any (integer) distance between 1 and D. If X > D then the frog cannot jump right across the pond. Luckily, there are leaves falling from a tree onto the surface of the pond, and the frog can jump onto and from the leaves.
+
+You are given a zero-indexed array A consisting of N integers. This array represents falling leaves. Initially there are no leaves. A[K] represents the position where a leaf will fall in second K.
+
+The goal is to find the earliest time when the frog can get to the other side of the pond. The frog can jump from and to positions 0 and X (the banks of the pond) and every position with a leaf.
+
+For example, you are given integers X = 7, D = 3 and array A such that:
+```
+A[0] = 1
+A[1] = 3
+A[2] = 1
+A[3] = 4
+A[4] = 2
+A[5] = 5
+```
+
+Initially, the frog cannot jump across the pond in a single jump. However, in second 3, after a leaf falls at position 4, it becomes possible for the frog to cross. This is the earliest moment when the frog can jump across the pond (by jumps of length 1, 3 and 3).
+```java
+class Solution { public int solution(int[] A, int X, int D); }
+```
+
+that, given a zero-indexed array A consisting of N integers, and integers X and D, returns the earliest time when the frog can jump to the other side of the pond. If the frog can leap across the pond in just one jump, the function should return 0. If the frog is never able to jump to the other side of the pond, the function should return −1.
+
+For example, given X = 7, D = 3 and array A such that:
+```
+A[0] = 1
+A[1] = 3
+A[2] = 1
+A[3] = 4
+A[4] = 2
+A[5] = 5
+```
+
+the function should return 3 as explained above.
+
+Assume that:
+- N is an integer within the range [0..100,000];
+- X and D are integers within the range [1..100,000];
+- each element of array A is an integer within the range [1..X-1].
+
+Complexity:
+- expected worst-case time complexity is O(N);
+- expected worst-case space complexity is O(X), beyond input storage (not counting the storage required for input arguments).
+
项目ID: #9611425
关于项目
有14名威客正在参与此工作的竞标,均价$24/小时
Hello My name is Ahmed, i'm a top rated freelancer. i worked over 100 projects and over 250 hours doing java projects. plus i passed freelancer java v3 exam with score 3.75 plus i got 2 java certificate 1Z0-803 and 1Z 更多
Hi, making this linear on N seemed not easy a first, but indeed not so bad, I can do it in O(D*N) time which is still linear in N, guess its fine.
The problem seems to be challenge....due to the constrains... I am thinking about dynamic programming.... also, find the shortest path on a graph. Which programming topic should be related with the solution?. Seems to 更多
Hi sir....! I will do problem just in hour. I have good skills in C/C++ programming and will write efficient and bugs free code for you.
Hello. How are u. I saw your description I have done several project like this. I'm an expert in Data Structures and Algorithms. And I know Java ,C/C++, C# and Python well. I'm interested this Project. I want 更多
I am a C/C++ programmer with over 10 years commercial experience. I could commit eight hours a day to this project, more if required. I could complete part of the project, at no expense to yourself, for your perusal 更多
I understand the project completely. I love solving these kinds of problems. I can probably make this project within one day (if I get free time from my job), but two days are needed for finishing the project with per 更多