Interview Question
Senior Software Development EngineersTeam: best buy
Country: United States
Interview Type: Written Test
/*
Essentially - generate a date-time range,
with spacing of 1 sec, each,
and then check if the string rep has 2 or less unique chars.
That is how one does a fully declarative coding.
Observe : en.wikipedia.org/wiki/ISO_8601
*/
def compute_interesting_times( s1, s2 ){
input_time_format = 'HH:mm:ss'
time_range = [ time(s1,input_time_format) : time(s2,input_time_format) + 'PT1S' : 'PT1S' ]
output_time_format = 'HHmmss'
x = select( time_range ) where {
s = str($.o, output_time_format)
size(set(s.value)) <= 2
}
size(x)
}
println( compute_interesting_times("15:15:00", "15:15:12") )
println( compute_interesting_times("22:22:21", "22:22:23") )
Solution in python
- Fernando May 24, 2017