Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 78666c3

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 8736fd0 commit 78666c3

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

.idea/workspace.xml

Lines changed: 22 additions & 22 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: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Given two integer arrays arr1 and arr2, return the minimum number of operations
3434
public class MakeArrayStrictlyIncreasing {
3535
public static void main(String[] args) {
3636
// Initialization.
37-
int[] arr1 = {1, 5, 3, 6, 7};
38-
int[] arr2 = {4, 3, 1};
37+
int[] arr1 = {0, 11, 6, 1, 4, 3};
38+
int[] arr2 = {5, 4, 11, 10, 1, 0};
3939
boolean isInitialValueChanged = false;
4040
int ans = 0;
4141

@@ -56,24 +56,24 @@ public static void main(String[] args) {
5656
if (!isValueFounded) {
5757
ans = -1;
5858
}
59-
60-
// Check for the last index.
61-
if (ans != -1 && arr1[arr1.length - 2] >= arr1[arr1.length - 1]) {
62-
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;
59+
}
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;
7369
}
7470
}
71+
if (!isValueFounded) {
72+
ans = -1;
73+
}
7574
}
7675

76+
7777
if (ans != -1) {
7878
for (int i = 1; i < arr1.length - 1; i++) {
7979
if (arr1[i] >= arr1[i + 1]) {

0 commit comments

Comments
 (0)