Count Times Using at Most Two Digits
Updated
Problem statement
Given start and end, count the whole-second timestamps in the same-day interval [start, end). Include the start and exclude the end.
A timestamp qualifies when its six digits in HH:MM:SS use at most two distinct decimal digits. Ignore the colons, but include all leading zeros. For example, 00:40:00 uses only 0 and 4.
Return the count. The special end value 24:00:00 represents the boundary immediately after the final second of the day; it is not a timestamp to count.
Function
countSpecialTimes(start: String, end: String) → intExamples
Example 1
start = "00:40:00"end = "00:40:10"return = 2Only 00:40:00 and 00:40:04 use the two digits 0 and 4 in this interval.
Example 2
start = "00:00:00"end = "00:00:11"return = 11The 11 timestamps ending in seconds 00 through 10 each use at most two digits. The endpoint ending in 11 is excluded.
Example 3
start = "12:12:12"end = "12:12:12"return = 0Equal endpoints give an empty half-open interval.
Constraints
- start and end each have exactly 8 characters.
- start is a valid 24-hour time in HH:MM:SS format, with hours 00 through 23 and minutes/seconds 00 through 59.
- end is a valid time in that same format or the boundary 24:00:00.
- start is no later than end, and the interval does not wrap across midnight.
More LSEG Online Assessment questions
- Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
- Maximum Word Count in a SentenceOA · Seen Jul 2025
- Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
- Smallest String After at Most One DeletionOA · Seen Jul 2025
- Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
- Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
- Transform a String with at Most One OperationOA · Seen Feb 2025
- Price Equity Options and ForwardsOA · Seen Dec 2024
- Maximum Sum of Non-Adjacent ElementsOA · Seen Sep 2024
- Return the Sentence with the Most WordsOA · Seen Sep 2024
Similar questions at other companies
- Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Add BinaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Address on Same PageNVIDIA · OANVIDIA interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Find the Missing Number from 1 to nGEP · OA
- Invert Ad Visibility BitsJP Morgan Chase · OAJP Morgan Chase interview questions
- Is This Date a Weekend?Salesforce · OASalesforce interview questions