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

Commit 370a649

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 4b8c754 commit 370a649

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

.idea/workspace.xml

Lines changed: 12 additions & 12 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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class MakeArrayStrictlyIncreasing {
3333
public static void main(String[] args) {
3434
// Initialization.
3535
int[] arr1 = {1, 5, 3, 6, 7};
36-
int[] arr2 = {1, 3, 2, 4};
37-
int ans = 1;
36+
int[] arr2 = {4, 3, 1};
37+
int ans = 0;
3838

3939
// Logic.
4040
for (int i = 0; i < arr1.length - 1; i++) {
@@ -44,18 +44,19 @@ public static void main(String[] args) {
4444
for (int j : arr2) {
4545
if (arr1[i + 1] > j) {
4646
valueFound = true;
47+
ans++;
4748
break;
4849
}
4950
}
5051
} else {
5152
for (int j : arr2) {
52-
if (arr1[i - 1] < j && arr1[i + 1] > j) {
53+
if (arr1[i - 1] <= j && arr1[i + 1] > j) {
5354
valueFound = true;
55+
ans++;
5456
break;
5557
}
5658
}
5759
}
58-
5960
if (!valueFound) {
6061
ans = -1;
6162
}
@@ -67,6 +68,7 @@ public static void main(String[] args) {
6768
for (int j : arr2) {
6869
if (arr1[arr1.length - 2] < j) {
6970
valueFound = true;
71+
ans++;
7072
break;
7173
}
7274
}
@@ -76,8 +78,9 @@ public static void main(String[] args) {
7678
}
7779

7880
// Display the result.
79-
if (ans == 1) {
81+
if (ans > 0) {
8082
System.out.println("Yes, array can be made strictly increasing using the values from another array.");
83+
System.out.println("Operation performed: " + ans);
8184
} else {
8285
System.out.println("No, array can not be made strictly increasing using the values from another array.");
8386
}

0 commit comments

Comments
 (0)