SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Given N values, Print "YES" if there exists atleast K negative values else Print "NO"
Given "N" values of an array, If the Number of Negative Integers Equals or Less than "K" Print "YES" else Print "NO"
Implementation:
# Following is the Python Implementation of the above given problem # Get the number of Test Cases t = int ( raw_input () ) # Loop Until the number of test cases become "0" while ( t > 0 ) : # Create an empty List list = [] # Get the values n (number of elements in the array) & k ( number of -ve no's) n, k = map ( int, raw_input().split() ) # Get the elements of the array as "String" s = raw_input() # Store the elements of String removing the white spaces in the list list = map ( int, s.split(' ') ) # To get the count of the numbers that are less than or equal to "0" in list # and also checks whether the count is less than "k" # If true, print YES if ( sum ( i <= 0 for i in list ) < k ) : print "YES" # Else Print NO else: print "NO" # Reduce the number of test cases by "1" for every test case evaluation t - = 1
PREVIOUS
NEXT
HOME