[OA] Strictly increasing sequence

Problem: Given an array arr[]. Need to make the array strictly increasing and if we can do so print "Yes" else "No".
Criteria: We can mke it strictly increasing by subtracting a value, say X, from arr[i] such that 0<=X<=arr[i].

Eg:
Input: arr[] = {2,15,10,15}
output: Yes
Expalanation: take X = 10 and subtract it from arr[1]. So the sequence becomes {2,5,10,15}, which is strictly increasing.

I tried the below brute force approach and 9/10 test cases passed. 10th TC was locked.
Approach:

  1. traversed from back
  2. for each element at index 'i', I moved backwards to 'j' where j<i and made changes inarr[j] as per the criteria required for strictly increasing sequence i.e. took X = 0 and increased until each pair becomes strictly increasing.

Any better approach for this?

Comments (3)