Created
February 24, 2016 02:04
-
-
Save thmain/402f579ab8393b4b50d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CheckArrayContainsAllElementsInGivenRange { | |
public Boolean find(int[] arrA, int x, int y) { | |
int range = y - x; | |
for (int i = 0; i < arrA.length; i++) { | |
if (arrA[i] >= x && arrA[i] <= y) { | |
int z = arrA[i] - x; | |
if (arrA[z] > 0) { | |
arrA[z] = arrA[z] * -1; | |
} | |
} | |
} | |
// for(int i=0;i<arrA.length;i++){ | |
// System.out.print(" " + arrA[i]); | |
// } | |
for (int i = 0; i < range; i++) { | |
if (arrA[i] > 0) | |
return false; | |
} | |
return true; | |
} | |
public static void main(String[] args) throws java.lang.Exception { | |
int[] arrA = { 11, 17, 13, 19, 15, 16, 12, 14 }; | |
int x = 12; | |
int y = 15; | |
CheckArrayContainsAllElementsInGivenRange i = new CheckArrayContainsAllElementsInGivenRange(); | |
System.out.println(i.find(arrA, x, y)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment