Frog one solution

已完成 已发布的 Feb 9, 2016 货到付款
已完成 货到付款

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).

+

C 编程

项目ID: #9611425

关于项目

14个方案 远程项目 活跃的Feb 25, 2016

授予:

lashabuxo

can do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it reallycan do it 更多

$24 USD 在1天内
(1条评论)
0.0

有14名威客正在参与此工作的竞标,均价$24/小时

vano101

Hello. It is easy assignment and it be completed in few hours of pure working time .

$21USD 在1天里
(635条评论)
6.8
AhmedLabib93

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 更多

$25 USD 在2天内
(49条评论)
4.7
mitkoradev

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.

$25USD 在1天里
(19条评论)
4.6
freelancerLatino

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 更多

$35 USD 在2天内
(18条评论)
4.7
xzan88

Hi, I can do this in C/C++................................................................................................................................................................................................ 更多

$20USD 在1天里
(10条评论)
3.4
israr2020

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.

$25USD 在1天里
(0条评论)
0.0
bookshop1989

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 更多

$34USD 在1天里
(1条评论)
0.0
Aean

C is my primary language, receiving 97/100 in COMP1917 and 98/100 in COMP1927 (Data Structures and Algorithms) at the University of New South Wales. I was also awarded the Macquarie Performance Prize Award for 3rd best 更多

$20USD 在1天里
(0条评论)
0.0
vw8040249vw

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 更多

$25USD 在1天里
(0条评论)
0.0
dwivediishere

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 更多

$29 USD 在2天内
(0条评论)
0.0
mhortis

I am an experienced C/C++/Java developer and I have coped with several projects, both small and more complex ones. I use Java and C++ daily for my regular job (I work as a telecommunications software engineer). I be 更多

$10USD 在1天里
(0条评论)
0.0