Menu
Coddy logo textTech

With Double Error Correction

Lesson 3 of 3 in Coddy's Interview Coding Challenges - Pack II course.

challenge icon

Challenge

Hard

You are given a signal as a string of zeros and ones.

Due to some harsh electromagnetic noise, sometimes (not so rarely) you are getting 0 instead of 1.

Assuming that each signal of 1's may have at most two error bits in it (meaning two 0's instead of 1's), return the length of the longest sequence that could possibly be sent to you with two errors only.

 

Example 1,

Input:

111100111011101110

Expected output:

11

Because both of the 0's between the two sequences of length 3 could be an error, connecting the three to a sequence of length 11.
 

Example 2:

Input:

0011110010110

Expected output:

7

Because the two 0's to the right of the sequence of length 4 could be an error, connecting it with the 1 bit, making them a sequence of length 7.

Try it yourself

#include <string.h>

int getLongestRepeatingOnes(char* s) {
    // Write code here
}

All lessons in Interview Coding Challenges - Pack II

1Challenges

Longest Repeating OnesWith Error CorrectionWith Double Error Correction