Problem: One can be obtained from one of the arrays.
Whether they are similar.
boolean areSimilar(int[] a, int[] b) { if (Arrays.equals(a,b)){ return true; } int[] c = Arrays.copyOf(a, a.length); boolean fl = true; label:for (int i = 0; i < c.length; i++){ for (int j = i + 1; j < c.length; j++){ int tmp = c[j]; c[j] = c[i]; c[i] = tmp; if (!Arrays.equals(c,b)){ fl = false; c[i] = c[j]; c[j] = tmp; }else{ fl = true; break label; } } } return fl; } Is it possible to somehow increase the speed of a particular piece of code? If not, I will be glad to see any other ideas that will be better for this task.