So I just failed my coding test due to running out of time. It was one of those codility tests only 70 minutes and 3 different problems, I passed on the first 2 questions however I ran out of time with the 3rd problem.
Here is the question that gave me issues
initially I assumed we would need to use the sliding window technique to get the contiguous 'x' and measure from there and I hacked at that solution for about 20 minutes but in the final 5 minutes out of pure desperation and need i came up with another solution that i did not get to fully flesh out in the official test.
The idea of the solution is in 3 simple broken up steps,
- separate the contiguous x
- sort by length
- decrement from your budget
this solution is magnitudes simpler to comprehend and a LOT easier to read. I may not have gotten the ability to benefit from coming up with this solution but hopefully someone reading this in the future will.
here it is in python
def solution(S, B):
# Implement your solution here
count = 0
#sliding window technique needed
arr = []
temparr = []
for index in S:
if index == "x":
temparr.append(index)
else:
arr.append(len(temparr))
temparr = []
arr = sorted(arr)
index = len(arr)-1
while B > 0 or index == 0:
if B >= arr[index]+1:
B -= arr[index]+1
count += arr[index]
index -= 1
return count
Top comments (4)
Good luck, you'll get it next time
I hate coding tests like this for interviews. They don't test that you'd be good for the job at all. A much better coding test is to give the interviewee a day or two to complete a mini project and show how you would actual perform under work conditions.
i dont hate coding tests since they are faster than a mini project but youre right about them not assessing how well you would do on the job.
I am so sorry to hear that! You will nail it next time! β¨