Last active
September 18, 2020 03:11
-
-
Save MukulLatiyan/a8998b88ea28eb7cdc8e929280d07007 to your computer and use it in GitHub Desktop.
Check if an array is sorted(GeeksForGeeks)
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
//Java Code for array checking problem given on school level on geeksforgeeks array school section. | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class GFG | |
{ | |
public static void main (String[] args) | |
{ | |
Scanner s = new Scanner(System.in); | |
int ntest = s.nextInt(); | |
while (ntest-- > 0){ | |
int size = s.nextInt(); | |
int[] arr = new int[size]; | |
for (int i = 0; i < size; i++){ | |
arr[i] = s.nextInt(); | |
} | |
//here using the clone object method,which is basically creating a replica of an array. | |
int[] ch = arr.clone(); | |
Arrays.sort(arr); | |
//now comparing them. | |
System.out.println(Arrays.equals(ch, arr)? 1: 0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment