Skip to content
Prev Previous commit
Next Next commit
Added test
  • Loading branch information
javadev committed Mar 6, 2025
commit d7076cceddad7571e928790dc15848b7ccd401b5
5 changes: 0 additions & 5 deletions src/main/java/g3401_3500/s3470_permutations_iv/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public int[] permute(int n, long k) {
return new int[0];
}
for (int z = 1; z < n; z++) {
boolean taken = false;
for (int j = 1; j <= n; j++) {
if (!used[j] && ((j & 1) != last)) {
int odd2 = odd;
Expand All @@ -106,14 +105,10 @@ public int[] permute(int n, long k) {
odd = odd2;
even = even2;
last = cp;
taken = true;
break;
}
}
}
if (!taken) {
return new int[0];
}
}
return ans.stream().mapToInt(i -> i).toArray();
}
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/g3401_3500/s3470_permutations_iv/SolutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@
class SolutionTest {
@Test
void permute() {
assertThat(new Solution().permute(4, 6), equalTo(new int[] {3, 4, 1, 2}));
assertThat(new Solution().permute(4, 6L), equalTo(new int[] {3, 4, 1, 2}));
}

@Test
void permute2() {
assertThat(new Solution().permute(3, 2), equalTo(new int[] {3, 2, 1}));
assertThat(new Solution().permute(3, 2L), equalTo(new int[] {3, 2, 1}));
}

@Test
void permute3() {
assertThat(new Solution().permute(2, 3), equalTo(new int[] {}));
assertThat(new Solution().permute(2, 3L), equalTo(new int[] {}));
}

@Test
void permute4() {
assertThat(
new Solution().permute(43, 142570305460935L),
equalTo(
new int[] {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 43, 40, 27, 36, 25, 34, 31, 32, 29, 28, 33, 24, 23, 26, 41, 42,
35, 38, 37, 30, 39
}));
}
}