Skip to content

Commit 48a099c

Browse files
author
Tushar Roy
committed
bug fixes
1 parent ebbfe01 commit 48a099c

4 files changed

Lines changed: 6 additions & 3 deletions

File tree

python/array/flip0smaximum1s.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def flip_0s_to_maximize_consecutive_1s(input, flips_allowed):
1010
else:
1111
if count_zero < flips_allowed:
1212
count_zero = count_zero + 1
13+
result = max(result, i - window_start + 1)
1314
else:
1415
while True:
1516
if input[window_start] == 0:

python/array/longestsamesumspan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def longest_span(input1, input2):
99
prefix1 = 0
1010
prefix2 = 0
1111
max_span = 0
12+
diff[0] = -1
1213
for i in range(len(input1)):
1314
prefix1 += input1[i]
1415
prefix2 += input2[i]

src/com/interview/array/Flip0sMaximum1s.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public int flip0sToMaximizeConsecutive1s(int input[], int flipsAllowed) {
2525
} else {
2626
if (countZero < flipsAllowed) {
2727
countZero++;
28+
result = Math.max(result, i - windowStart + 1);
2829
} else {
2930
while(true) {
3031
if (input[windowStart] == 0) {

src/com/interview/array/LongestSameSumSpan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public int longestSpan(int input1[], int input2[]) {
2424
Map<Integer, Integer> diff = new HashMap<>();
2525
int prefix1 = 0, prefix2 = 0;
2626
int maxSpan = 0;
27+
diff.put(0, -1);
2728
for (int i = 0; i < input1.length ; i++) {
2829
prefix1 += input1[i];
2930
prefix2 += input2[i];
@@ -38,9 +39,8 @@ public int longestSpan(int input1[], int input2[]) {
3839
}
3940

4041
public static void main(String args[]) {
41-
int input1[] = {0, 1, 0, 1, 1, 1, 1};
42-
int input2[] = {1, 1, 1, 1, 1, 0, 1};
43-
42+
int input1[] = {1, 0, 0, 1, 1, 0};
43+
int input2[] = {0, 1, 1, 0, 1 ,1};
4444
LongestSameSumSpan lsss = new LongestSameSumSpan();
4545
System.out.print(lsss.longestSpan(input1, input2));
4646
}

0 commit comments

Comments
 (0)