Wipro Coding Question 4

Digital Machine

Digital Machine is one of the coding question asked in previous wipro Elite NTH Exam. In this article, we will discuss about the Maximum signal problem with their solution in C++ and Java. 

Wipro Coding Questions

Question 4

A digital machine generates binary data which consists of a string of 0s and 1s. A maximum signal M, in the data, consists of the maximum number of either 1s or 0s appearing consecutively in the data but M can’t be at the beginning or end of the string. Design a way to find the length of the maximum signal.

Input
The first line of the input consists of an integer N, representing the length of the binary string. The second line consists of a string of length N consisting of 0s and 1s only.

Output
Print an integer representing the length of the maximum signal.

Example
Example 1:

Input
6
101000

Output
1

Explanation
For 101000, M can be 0 at the second index or at the third index so in both cases max length = 1.

Example2:

Input
9
101111110

Output
6

Explanation
For 101111110, M = 111111 so maxlength = 6.

4 comments on “Wipro Coding Question 4”


  • lastwish

    Try this easy and small length of code . 🙂 in JAVA (code = DigitalMachine)
    import java.util.*;
    public class Main{
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    sc.nextLine();
    String binary = sc.nextLine();
    int count = 0;
    for(int i =1 ; i<N-1 ; i++){
    if(binary.charAt(i)=='1'){
    count++;
    }
    else{
    continue;
    }
    }
    System.out.print(count);
    sc.close();
    }
    }