We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0668e5d commit 5be9432Copy full SHA for 5be9432
src/main/java/com/hackerrank/contests/SwappingInAnArray.java
@@ -10,9 +10,14 @@
10
* @since 04/11/2018
11
*/
12
public class SwappingInAnArray {
13
- // Complete the swapToSort function below.
+
14
+ /**
15
+ * The problem asks if we can sort the array with only one swap.
16
+ *
17
+ * @param a array to sort
18
+ * @return 0 if already sorted, 1 if it can be sorted with one swap, -1 otherwise
19
+ */
20
static int swapToSort(int[] a) {
- // Return -1 or 0 or 1 as described in the problem statement.
21
int swaps = 0;
22
for (int i=0; i < a.length-1; i++) {
23
int swapIndex = i;
0 commit comments