Min and Max

Sort by

recency

|

353 Discussions

|

  • + 0 comments
    import numpy as np
    N,M = map(int,input().split())
    arr = np.array([input().split() for _ in range(N)],int)
    arr = np.min(arr,axis=1)
    print(np.max(arr))
    
  • + 0 comments

    import numpy as np n , m = [int(c) for c in input().split()] nparr = np.empty(shape=(n, m),dtype = 'i4')

    print(n ,m)

    print(nparr)

    for i in range(n): lst = [int(c) for c in input().split()] for j in range(m): nparr[i][j] = lst[j] nparr = np.min(nparr, axis=1) nparr = np.max(nparr) print(nparr)

  • + 0 comments
    import numpy as np
    N,M = map(int,input().split())
    my_array = np.array([list(map(int,input().split())) for _ in range(N)])
    print(np.max(np.min(my_array,axis=1)))
    
  • + 0 comments

    My compact, one-liner solution…

    print(np.loadtxt(sys.stdin, int).min(axis=1).max())
    

    After I submitted this solution, it passed all the tests, and I began posting about it here, I realized something. I didn't skip the first line of input containing N and M as I usually do.

    But my one-liner passed all the tests anyway! I'm just lucky that making those two values part of the array didn't make any difference in the results.

    The solution I should've written was…

    _ = input()  # We don't need N or M.  Skip them!
    print(np.loadtxt(sys.stdin, int).min(axis=1).max())
    

    Inspired by another user's comments about using N and M, although they're not necessary, I wrote a solution that uses them…

    print(((NM := list(map(int, input().split()))),
        np.loadtxt(sys.stdin, int)[:NM[0], :NM[1]].min(axis= 1).max())[1])
    
  • + 3 comments

    Though, range M is not required, but its still always a good practice to do so to exactly respect the question asked. And that's why I intentionally invoked this to keep the N * M Matrix. What do you think? Please let me know your opinion?

    import numpy
    
    N, M = list(map(int, input().split()))
    
    array_lst =[]
    
    for _ in range(N):
        inp = input().split()
        lst = [int(inp[i]) for i in range(M)]
        array_lst.append(lst)
        
    np_array = numpy.array(array_lst)
    max_array= numpy.min(np_array, axis= 1)
    print(numpy.max((max_array)))