Skip to content

Commit 1627f31

Browse files
committed
Corrected the invalid answer: Have implemented the program to find whether the array can be made strictly increasing using the values from another array.
1 parent fdd5345 commit 1627f31

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

.idea/workspace.xml

Lines changed: 8 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/com/raj/MakeArrayStrictlyIncreasing.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,10 @@ public static void main(String[] args) {
5757
ans = -1;
5858
}
5959
}
60-
// Check for the last index.
61-
if (ans != -1 && arr1[arr1.length - 2] >= arr1[arr1.length - 1]) {
62-
boolean isValueFounded = false;
63-
for (int j : arr2) {
64-
if (arr1[arr1.length - 2] < j) {
65-
arr1[arr1.length - 1] = j;
66-
isValueFounded = true;
67-
ans++;
68-
break;
69-
}
70-
}
71-
if (!isValueFounded) {
72-
ans = -1;
73-
}
74-
}
75-
7660

7761
if (ans != -1) {
7862
for (int i = 1; i < arr1.length - 1; i++) {
63+
7964
if (arr1[i] >= arr1[i + 1]) {
8065
boolean isValueFounded = false;
8166
if (initialValueChangedIndex != i) {
@@ -108,6 +93,22 @@ public static void main(String[] args) {
10893
}
10994
}
11095

96+
// Check for the last index.
97+
if (ans != -1 && arr1[arr1.length - 2] >= arr1[arr1.length - 1]) {
98+
boolean isValueFounded = false;
99+
for (int j : arr2) {
100+
if (arr1[arr1.length - 2] < j) {
101+
arr1[arr1.length - 1] = j;
102+
isValueFounded = true;
103+
ans++;
104+
break;
105+
}
106+
}
107+
if (!isValueFounded) {
108+
ans = -1;
109+
}
110+
}
111+
111112
// Display the result.
112113
if (ans > 0) {
113114
System.out.println("Yes, array can be made strictly increasing using the values from another array.");

0 commit comments

Comments
 (0)