3/6 test cases passed and 1 wrong and 2 TLE. If this is leetcode question add link in comments or else lets discuss best solution for this.
Given a array ( 1 indexing ) contains N elements, print the maximum value of x for each element in the array.
For each element a[i], maximum value of x such that a[1] to a[x] are divisible by a[i].
Input format: First line contains N, second line contains N elements of array.
Constraint:
1<=N<= 3x10^5
1<= x <= N
1<=A[i] <= 10^6Sample Input:
3
9 3 1Sample Output: 1 2 3
for 9, it can be divided by 9 only so, print 1
for 3, it can be divided by 9 and 3. so, print 2 (index value of last element which is divisible)
for 1, it can be divided by 9, 3 and 1. so, print 3 (index value of last element which is divisible)