diff --git a/Python-Developer/question1.py b/Python-Developer/question1.py index e44cbb8..f057920 100644 --- a/Python-Developer/question1.py +++ b/Python-Developer/question1.py @@ -1,7 +1,12 @@ def select_max(array): # write your function here # do NOT use the built-in max() function - pass + max_value = array[0] + + for i in array: + if i>max_value: + max_value = i + return max_value if __name__ == "__main__": diff --git a/Python-Developer/question2.py b/Python-Developer/question2.py index c084ca5..edbe990 100644 --- a/Python-Developer/question2.py +++ b/Python-Developer/question2.py @@ -5,9 +5,27 @@ def center_zeros(array): # write your function here # center means the floor(x / 2) where floor means rounding a float (decimal number) down to the nearest integer # i.e. floor(1) = 1, floor(1.5) = 1, floor(1.75) = 1, floor(2) = 2 - pass + count_zero = 0 + for i in array: + if i==0: + count_zero+=1 + + mid = floor(int(len(array)/2)) + li= [] + + for i in range(0,(mid-count_zero)+1): + if array[i]!=0: + li.append(array[i]) + + for i in range(count_zero): + li.append(0) + + for i in range(mid-1,len(array)): + if array[i]!=0: + li.append(array[i]) + return li if __name__ == "__main__": # write your debug code here - pass \ No newline at end of file + pass diff --git a/Python-Developer/question_3.py b/Python-Developer/question_3.py index 8f41597..7057464 100644 --- a/Python-Developer/question_3.py +++ b/Python-Developer/question_3.py @@ -1,6 +1,20 @@ +def minRecursive(threshold, points): + if len(points)==1: + return 0 + if len(points)==2: + return 1 + if len(points)>=3: + return minRecursive(threshold-points[0], points[2:len(points)]) + 1 + def minimum_points(threshold, points): # write your code here - pass + if len(points) <=0: + return 0 + #since array is sorted, we check the difference between the max and min points and compare with the threshold, if less perform all the problems + if points[len(points)-1] - points[0] < threshold: + return len(points) + else: + return minRecursive(threshold, points) +1 if __name__ == "__main__":