Skip to content

Commit c16de41

Browse files
Create Interview7
1 parent 69652b5 commit c16de41

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/main/java/pramp/Interview7

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Pramp {
2+
3+
public static void main(String[] args) {
4+
String pramp = "Practice Makes Perfect";
5+
System.out.println(pramp);
6+
}
7+
8+
// a = {5, 10, 4, 1, 2}; l == 5
9+
// i = {0, 1, 2, 3, 4}
10+
// {2, 10, 4, 1, 5}
11+
// {10, 2, 4, 1, 5}
12+
// {10, 2, 1, 4, 5}
13+
// {1, 2, 3, 4, 5}
14+
15+
// [0, MAX_VALUE]
16+
17+
public static int get(int[] n) {
18+
if (n==null || n.length() == 0)
19+
return 1;
20+
21+
for (int i=0; i<n.length(); i++) {
22+
while (n[i] != i + 1 && n[i] <= n.length && n[i] > 0) {
23+
int temp = n[i]; // 1
24+
n[i] = n[temp - 1]; // 10
25+
n[temp - 1] = temp; // n[0] = 1
26+
}
27+
}
28+
29+
for (int i=0; i<n.length(); i++)
30+
if (n[i] != i + 1)
31+
return i + 1;
32+
33+
return n.length() + 1;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)