Skip to content

Commit 270a13b

Browse files
committed
[CountingElements] Codility-PermCheck
1 parent bfd267e commit 270a13b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
| 01 | | [Codility-Lesson2 CyclicRotation](./src/Array/CyclicRotation) | |
5252
| 02 | | [Codility-Lesson2 OddOccurrencesInArray](./src/Array/OddOccurrencesInArray) | |
5353
| 03 | | [Codility-Lesson4 FrogRiverOne](./src/Array/FrogRiverOne) | |
54+
| 04 | | [Codility-Lesson4 PermCheck](./src/Array/PermCheck) | |
5455

5556
### Stack
5657

src/Array/PermCheck/Main.java

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

src/Array/PermCheck/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## [Codility - Lesson 4 Counting Elements] PermCheck
2+
3+
> Detected time complexity : **O(N) or O(N * log(N))**
4+
5+
![image](https://user-images.githubusercontent.com/22045163/104466321-6fbf7200-55f8-11eb-87f8-949a7dd4f0c1.png)

0 commit comments

Comments
 (0)