Skip to content

Commit 7acd739

Browse files
committed
[CountingElements] Codility-FrogRiverOne
1 parent 9807b9e commit 7acd739

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| :-: | :-: | :-------------------------------------------------------------------------- | :--- |
3939
| 01 | | [Codility-Lesson2 CyclicRotation](./src/Array/CyclicRotation) | |
4040
| 02 | | [Codility-Lesson2 OddOccurrencesInArray](./src/Array/OddOccurrencesInArray) | |
41+
| 03 | | [Codility-Lesson4 FrogRiverOne](./src/Array/FrogRiverOne) | |
4142

4243
### Stack
4344

Diff for: src/Array/FrogRiverOne/Main.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Array.FrogRiverOne;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Solution sol = new Solution();
6+
System.out.println(sol.solution(5, new int[]{1, 3, 1, 4, 2, 3, 5, 4}));
7+
}
8+
}
9+
10+
class Solution {
11+
public int solution(int X, int[] A) {
12+
boolean[] leaves = new boolean[X+1];
13+
int count = 0;
14+
15+
for (int i = 0; i < A.length; i ++) {
16+
if (!leaves[A[i]]) {
17+
leaves[A[i]] = true;
18+
count ++;
19+
}
20+
if (count == X) return i;
21+
}
22+
23+
return -1;
24+
}
25+
}

Diff for: src/Array/FrogRiverOne/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## [Codility - Lesson 4 Counting Elements] FrogRiverOne
2+
3+
> Detected time complexity : **O(N)**
4+
5+
![image](https://user-images.githubusercontent.com/22045163/103459726-86420f80-4d54-11eb-9e07-a5f901f71c04.png)
6+
![image](https://user-images.githubusercontent.com/22045163/103459780-ce613200-4d54-11eb-9505-ffec8ef16489.png)

0 commit comments

Comments
 (0)