Answer: THALES GROUP Hiring | Online Assessment Interview Question | On-Campus OA (2023)

Answer · Posted Jun 2026

Approach Instead of checking every number, use a mathematical formula. The count of odd numbers from 0 to n is: (n + 1) / 2 Therefore, Odds(low...high) = Odds(0...high) - Odds(0...low-1) Which simplifies to: (high + 1) / 2 - low / 2 Strategy Count odd numbers from 0 to high. Count odd numbers from 0 to low - 1. Subtract the two counts. Return the answer. Java Code class Solution { public int countOdds(int low, int high) { return ...

The full answer & interview discussion are available to premium members.

Log in Create a free account