Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 139de9f

Browse files
p206
1 parent 56725c7 commit 139de9f

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

‎AllQuestions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,7 @@ and the nodes in the last level are filled starting from the left.
32303230
Given an integer, find the next permutation of it in absolute order. For
32313231
example, given 48975, the next permutation would be 49578.
32323232

3233-
## Problem-206:waxing_crescent_moon:
3233+
## [Problem-206](src/main/java/in/ashwanik/dcp/problems/p181_210/p206):sunny:
32343234

32353235

32363236
> This problem was asked by Twitter.

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ Solutions to the coding problems from [Daily coding problem](https://dailycoding
6565
|[P9](src/main/java/in/ashwanik/dcp/problems/p1_30/p9)|[P92](src/main/java/in/ashwanik/dcp/problems/p91_120/p92)|[P167](src/main/java/in/ashwanik/dcp/problems/p151_180/p167)|[P177](src/main/java/in/ashwanik/dcp/problems/p151_180/p177)|
6666

6767

68-
## **Dropbox (4)**
68+
## **Twitter (4)**
6969
| | | | |
7070
|--|--|--|--|
71-
|[P36](src/main/java/in/ashwanik/dcp/problems/p31_60/p36)|[P39](src/main/java/in/ashwanik/dcp/problems/p31_60/p39)|[P54](src/main/java/in/ashwanik/dcp/problems/p31_60/p54)|[P172](src/main/java/in/ashwanik/dcp/problems/p151_180/p172)|
71+
|[P11](src/main/java/in/ashwanik/dcp/problems/p1_30/p11)|[P16](src/main/java/in/ashwanik/dcp/problems/p1_30/p16)|[P112](src/main/java/in/ashwanik/dcp/problems/p91_120/p112)|[P206](src/main/java/in/ashwanik/dcp/problems/p181_210/p206)|
7272

7373

74-
## **Twitter (3)**
75-
| | | |
76-
|--|--|--|
77-
|[P11](src/main/java/in/ashwanik/dcp/problems/p1_30/p11)|[P16](src/main/java/in/ashwanik/dcp/problems/p1_30/p16)|[P112](src/main/java/in/ashwanik/dcp/problems/p91_120/p112)|
74+
## **Dropbox (4)**
75+
| | | ||
76+
|--|--|--|--|
77+
|[P36](src/main/java/in/ashwanik/dcp/problems/p31_60/p36)|[P39](src/main/java/in/ashwanik/dcp/problems/p31_60/p39)|[P54](src/main/java/in/ashwanik/dcp/problems/p31_60/p54)|[P172](src/main/java/in/ashwanik/dcp/problems/p151_180/p172)|
7878

7979

8080
## **Snapchat (3)**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A permutation can be specified by an array P, where P[i] represents the location
2+
of the element at i in the permutation. For example, [2, 1, 0] represents the
3+
permutation where elements at the index 0 and 2 are swapped.
4+
5+
Given an array and a permutation, apply the permutation to the array. For
6+
example, given the array ["a", "b", "c"] and the permutation [2, 1, 0], return
7+
["c", "b", "a"].
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package in.ashwanik.dcp.problems.p181_210.p206;
2+
3+
class Solution {
4+
5+
//a b c
6+
//2 1 0
7+
8+
void permuteArray(char[] array, int[] indices) {
9+
if (array == null || indices == null) {
10+
return;
11+
}
12+
for (int index = 0; index < array.length; index++) {
13+
int temp = indices[index];
14+
indices[index] = indices[temp];
15+
indices[temp] = temp;
16+
17+
int k = array[index] - 'a';
18+
array[index] = array[temp];
19+
array[temp] = array[k];
20+
}
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package in.ashwanik.dcp.problems.p181_210.p206;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
6+
7+
8+
public class SolutionTest {
9+
@Test
10+
void testPermutation() {
11+
char[] array = {'a', 'b', 'c'};
12+
int[] indices = {2, 1, 0};
13+
new Solution().permuteArray(array, indices);
14+
assertArrayEquals(new char[]{'c', 'b', 'c'}, array);
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /