3 ms·
You can always scan through the array, rescale everything by 1/max(input). Then the sleep part is O(1) and the scan part is O(n) -> O(n) total.
by davrosthedalek 12y ago
You can always scan through the array, rescale everything by 1/max(input). Then the sleep part is O(1) and the scan part is O(n) -> O(n) total.
- JoshTriplett 12y agoDivision isn't O(1) for arbitrary values (potentially larger than a machine word).