|
int t;/*TestCases */ |
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
|
t = Integer.parseInt(br.readLine()); |
|
for(int k=0;k<t;k++){//O(n ^ 2) |
|
int n;int[] B ;String[] s;/* SizeOfArray,Resultant Array, Temporay Array */ |
|
Scanner sc;//Scanner |
|
n = Integer.parseInt(br.readLine()); |
|
sc = new Scanner(br); |
|
B = new int[n]; |
|
for(int i=0;i<n;i++){// Contain Program to find all ith element of B using A |
|
int key = sc.nextInt(); |
|
if(i!=0){ |
|
B[i] = (int) Math.ceil((double)B[i-1]/key)*key; |
|
}else B[i]=key; |
|
} |
|
|
|
for(int i:B) |
|
System.out.print(i+" "); |
|
System.out.println(); |
|
sc.close(); |
|
} |
Here my solution is only partially accepted(pass 7 test cases) in problem statement HackerEarthProblemNon-Increasing Array
And i won't able to find a way to optimise my code or any other accepted solution written in java for this particular problem that pass these tests.
HackerRankSolved/Extras/HackerEarth/DataStructures/Arrays/Non-decreasingArrays/Solution.java
Lines 21 to 41 in c86b1da
Here my solution is only partially accepted(pass 7 test cases) in problem statement HackerEarthProblemNon-Increasing Array
And i won't able to find a way to optimise my code or any other accepted solution written in java for this particular problem that pass these tests.