H
H
HellYeahOmg2019-04-30 11:33:49
Algorithms
HellYeahOmg, 2019-04-30 11:33:49

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

2 answer(s)
A
Anton Shvets, 2019-04-30
@HellYeahOmg

display the average sums by category and compare.

L
lu1ssuarez, 2019-04-30
@lu1ssuarez

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 question

Ask a Question

731 491 924 answers to any question