Answer: LOKOAI Interview Online Assessment Question | On-Campus (2024)
Answer · Posted Jun 2026
Approach Instead of iterating through the range: Number of odd integers from 0 to n is: (n + 1) / 2 Therefore: Odds in [low, high] = Odds(0...high) - Odds(0...low-1) Formula: (high + 1) / 2 - low / 2 Strategy Use mathematical counting instead of traversal. Works efficiently even for: high = 10^9 Java Code class Solution { public int countOdds(int low, int high) { return (high + 1) / 2 - low / 2; } } Time Complexity ...
The full answer & interview discussion are available to premium members.
Log in Create a free account