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

Commit fdd5345

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 78666c3 commit fdd5345

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

.idea/workspace.xml

Lines changed: 23 additions & 8 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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void main(String[] args) {
3636
// Initialization.
3737
int[] arr1 = {0, 11, 6, 1, 4, 3};
3838
int[] arr2 = {5, 4, 11, 10, 1, 0};
39-
boolean isInitialValueChanged = false;
39+
int initialValueChangedIndex = 0;
4040
int ans = 0;
4141

4242
// Logic.
@@ -78,12 +78,12 @@ public static void main(String[] args) {
7878
for (int i = 1; i < arr1.length - 1; i++) {
7979
if (arr1[i] >= arr1[i + 1]) {
8080
boolean isValueFounded = false;
81-
if (!isInitialValueChanged) {
81+
if (initialValueChangedIndex != i) {
8282
for (int j : arr2) {
8383
if (arr1[i - 1] < j) {
8484
arr1[i] = j;
8585
isValueFounded = true;
86-
isInitialValueChanged = true;
86+
initialValueChangedIndex = i;
8787
i--;
8888
ans++;
8989
break;
@@ -95,7 +95,6 @@ public static void main(String[] args) {
9595
if (arr1[i] < j) {
9696
arr1[i + 1] = j;
9797
isValueFounded = true;
98-
isInitialValueChanged = false;
9998
ans++;
10099
break;
101100
}

0 commit comments

Comments
 (0)