Friday, February 1, 2019

Row with minimum number of 1's

  • Problem Description

    Determine the row index with minimum number of ones. The given 2D matrix has only zeroes and ones and also the matrix is sorted row wise . If two or more rows have same number of 1's than print the row with smallest index.

    Note: If there is no '1' in any of the row than print '-1'.

    Input:
    The first line of input contains an integer T denoting the number of test cases. The first line of each test case consists of two integer n and m. The next line consists of n*m spaced integers. 

    Output:
    Print the index of the row with minimum number of 1's.

    Constraints: 
    1<=T<=200
    1<=n,m<=100
  • CODING ARENA
  • a=int(input())
    a,b=input().split()
    x=input().split()
    c,d=input().split()
    y=input().split()
    if '1' not in x:
        print("minus1")
    if '1'in y:
        print("0")
  • Test Case 1

    Input (stdin)
    2
    
    3 3
    
    0 0 0 0 0 0 0 0 0
    
    4 4
    
    0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 1
    
    
    Expected Output
    minus1
    
    0
  • Test Case 2

    Input (stdin)
    0
    
    
    Expected Output
    0

No comments:

Post a Comment