@@artemis_134 a snazzy mathy solution may exist, that could be true. but given the format of the data, you'll have to read all the items at least once; which is what you're doing. and if you were to attempt to put the data into a better format, you'd still have to read everything; which still would be O(N). so although you may be able to certainly speed up the runtime performance, the algorithmic runtime complexity remains linear.
I think both algos can be reduced to an O(N) runtime so it's probably safe to assume this is the best you can do here.
It feels like something that has a snazzy mathy solution I'm just not aware of, but I might be overthinking it 🤷♀️
@@artemis_134 a snazzy mathy solution may exist, that could be true. but given the format of the data, you'll have to read all the items at least once; which is what you're doing. and if you were to attempt to put the data into a better format, you'd still have to read everything; which still would be O(N). so although you may be able to certainly speed up the runtime performance, the algorithmic runtime complexity remains linear.