fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int t = sc.nextInt();
  14. while(t-- > 0)
  15. {
  16. int n = sc.nextInt();
  17. int a[] = new int[n];
  18. for(int i = 0; i < n; i++)
  19. {
  20. a[i] = sc.nextInt();
  21. }
  22.  
  23. int flag = 0;
  24. for(int j = 0; j < (n -1); j++)
  25. {
  26. if(a[j+1] < a[j])
  27. {
  28. flag = 1;
  29. n = n/2;
  30. break;
  31. }
  32.  
  33. }
  34.  
  35. int len = uniqueSort(a, 0, n, flag);
  36. System.out.println(len);
  37. }
  38. }
  39.  
  40. public static int uniqueSort(int a[], int index, int length, int flag)
  41. {
  42. if(flag == 0)
  43. return length;
  44.  
  45. flag = 0;
  46. for(int i = index; i < length - 1; i++)
  47. {
  48. if(a[i+1] < a[i])
  49. {
  50. flag = 1;
  51. length = length/2;
  52. break;
  53. }
  54.  
  55. }
  56.  
  57.  
  58. return uniqueSort(a,index,length,flag);
  59. }
  60.  
  61. }
Success #stdin #stdout 0.1s 35496KB
stdin
3
4
1 2 2 4
8
11 12 1 2 13 14 3 4
4
7 6 5 4
stdout
4
2
1