HackerRank Zeros and Ones problem solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Zeros and Ones problem solution in Python – In this zero and One’s problem in python programming, You are given the shape of the array in the form of space-separated integers, each integer representing the size of different dimensions, your task is to print an array of the given shape and integer type using the tools numpy.zeros and numpy.ones.zerosThe zeros tool returns a new array with a given shape and type filled with ‘s.import numpy print numpy.zeros((1,2)) #Default type is float #Output : [[ 0. 0.]] print numpy.zeros((1,2), dtype = numpy.int) #Type changes to int #Output : [[0 0]] onesThe ones tool returns a new array with a given shape and type filled with ‘s.import numpy print numpy.ones((1,2)) #Default type is float #Output : [[ 1. 1.]] print numpy.ones((1,2), dtype = numpy.int) #Type changes to int #Output : [[1 1]] HackerRank Zeros and Ones solution in Python 2.import numpy N = map(int, raw_input().split()) print numpy.zeros(N, dtype = numpy.int) print numpy.ones(N, dtype = numpy.int)Zeros and Ones solution in Python 3.import numpy nums = tuple(map(int, input().split())) print (numpy.zeros(nums, dtype = numpy.int)) print (numpy.ones(nums, dtype = numpy.int)) Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import numpy input_number=tuple(map(int,raw_input().strip().split())) print numpy.zeros(input_number, dtype = numpy.int) print numpy.ones(input_number, dtype = numpy.int)Problem solution in pypy3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import numpy as np dims = input().split() dims = [int(i) for i in dims] print(np.zeros(tuple(dims),dtype=np.int)) print(np.ones(tuple(dims),dtype=np.int)) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython