+ 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

18th Dec 2017, 2:31 AM
Ronak Pareek
Ronak Pareek - avatar
10 odpowiedzi
18th Dec 2017, 2:32 PM
LukArToDo
LukArToDo - avatar
18th Dec 2017, 5:40 PM
Justine Ogaraku
Justine Ogaraku - avatar
18th Dec 2017, 7:04 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 4
No problem buddy Happy coding ✌🏻
18th Dec 2017, 12:03 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 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)
18th Dec 2017, 3:02 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 3
When I input 3 4 5 6 , ur code prints "Yes", but if I input 4 5 6 7 the code print "No"
18th Dec 2017, 11:52 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 2
@sebastian The first input is size of array
18th Dec 2017, 11:56 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 2
You're right, I forgot that It works now :) (I'll edit mine)
18th Dec 2017, 12:01 PM
Sebastián Zapata
Sebastián Zapata - avatar
18th Dec 2017, 11:44 PM
Luc Hariman Randrianomenjanahary
Luc Hariman Randrianomenjanahary - avatar
0
https://code.sololearn.com/cYLFyM58wPrT/?ref=app
25th Dec 2017, 12:23 AM
Daniel
Daniel - avatar