-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrictlyIncreasingArray.java
More file actions
44 lines (41 loc) · 1.29 KB
/
StrictlyIncreasingArray.java
File metadata and controls
44 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package array_Programming.advance.day_14;
//11.Check If Array Can Be Made Strictly Increasing by Removing One
//Element
import java.util.*;
public class StrictlyIncreasingArray
{
public static boolean canBeIncreasing(int[] arr)
{
int count = 0;
for (int i = 0; i < arr.length - 1; i++)
{
if (arr[i] >= arr[i + 1])
{
count++;
if (count > 1)
return false;
if (i > 0 && arr[i - 1] >= arr[i + 1])
{
arr[i + 1] = arr[i];
}
}
}
return true;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter size of array: ");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.println("Enter " + n + " elements:");
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
System.out.println("Array: " + Arrays.toString(arr));
if (canBeIncreasing(arr))
System.out.println("YES, array can be made strictly increasing");
else
System.out.println("NO, array cannot be made strictly increasing");
sc.close();
}
}