+ 5
[ CHALLENGE 3 ] Min-Max
Given an array of integers . Check if all the numbers between minimum and maximum number in array exist's within the array . Print 'YES' if numbers exist otherwise print 'NO'(without quotes). Input: Integer N denoting size of array Next line contains N space separated integers denoting elements in array Output: Output your answer Constraints: 1<= N <= 1000 1<= a[i] <= 100 SAMPLE INPUT 6 4 2 1 3 5 6 SAMPLE OUTPUT YES Explanation : min 1 max 6 all number between them are 2345 are present so YES
10 Respuestas
+ 15
My one-linear Python code
https://code.sololearn.com/cMyrpfNB4wHA/?ref=app
+ 4
No problem buddy
Happy coding ✌🏻
+ 3
# Python 2.7
arr = raw_input()
arr = arr[3:] # Edited!
arr = arr.split() # Turn string into a list
# Turn elements into integers
arr = map(lambda x: int(x), arr)
maximum = max(arr)
minimum = min(arr)
for i in range(minimum+1, maximum):
if i not in arr:
print "NO"
break
elif i == maximum - 1:
print "YES"
# This covers the case when arr = [1, 2] or
# arr = [1,1,1] , because the for bucle
# doesn't print anything
if abs(maximum - minimum) <= 1:
print "YES"
#(it seems a Dcoder app problem? I swear yes xD)
+ 3
When I input 3 4 5 6 , ur code prints "Yes", but if I input 4 5 6 7 the code print "No"
+ 2
@sebastian
The first input is size of array
+ 2
You're right, I forgot that
It works now :)
(I'll edit mine)
0
https://code.sololearn.com/cYLFyM58wPrT/?ref=app