Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interview Questions #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Python-Developer/question1.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down
22 changes: 20 additions & 2 deletions Python-Developer/question2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
pass
16 changes: 15 additions & 1 deletion Python-Developer/question_3.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down