+ 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 Answers
+ 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