Amazon Interview Question
SDE1sCountry: United States
How does the range matter on the split? The given size of the original list is what matters right? And i dont see anywhere in the question that you are allowed to remove duplicates. Is that an assumption? Its a bit confusing. Can the original poster please provide a couple more examples of inputs / outputs?
Thank you
first = ip[0]
first_list = []
first_list.append(first)
second_list = []
second_list_offset = 0
for each in ip[1:]:
if each == first+1 and len(first_list) < 5:
first_list.append(each)
first = each
else:
second_add = True
if second_list_offset !=0:
if each != second_list[second_list_offset-1] +1 :
print("Not possible")
second_add = False
if second_add is True and len(second_list) < 5:
second_list.append(each)
second_list_offset+=1
else:
print("Not possible")
High level steps:
a. Sort array
b. Remove duplicates
c. For every step, check if the value of {CurrentElement + 5} - {CurrElement} = 5
Following is c++ code:
- ITWala May 03, 2018