Answer the question
In order to leave comments, you need to log in
Is such an algorithm possible?
Recently I was at an interview, they gave a test task in which it was necessary to come up with an algorithm.
The algorithm should suggest a purchase category based on the amount and date of purchase.
You need to rely only on existing operations (!).
Is it possible to come up with something similar? I answered in the negative.
Answer the question
In order to leave comments, you need to log in
Using binary search in the sorted purchase history, we are looking for the nearest sums Sn1+, Sn1-
We look at their categories:
- k and k --> the category of our sum Sn is k
- k and k+1 --> we set k+1 or calculate the difference of sums by modulo (Sn1+)-Sn and (Sn1-)-Sn. Let's say (Sn1-)-Sn is min, put the category k
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question