Interview Question for Senior Software Development Engineers


Team: best buy
Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in python

def compute_interesting_times(s, t):
    def convert_number(x):
        pad = ''
        if x < 10:
            pad = '0'
        return pad + str(x)
        
    # Check times
    if s > t:
        raise ValueError("The init time is greater than the finishing time")
        
        
    # Parse times
    h_c, m_c, s_c = map(lambda x: int(x), s.split(':'))
    h_f, m_f, s_f = map(lambda x: int(x), t.split(':'))
    total = 0
    
    while not (h_c == h_c and m_c == m_f and s_c == s_f):
        # Transform the numbers into a proper string and
        # check if we have to increase the total
        a = '{}{}{}'.format(convert_number(h_c),
                            convert_number(m_c), 
                            convert_number(s_c))
        if len(set(a)) <= 2:
            total += 1
        
        # Update the time counters
        s_c += 1
        if s_c == 60:
            s_c = 0
            m_c += 1
            if m_c == 60:
                m_c = 0
                h_c += 1

    # Check if the finishing time is an interesting time
    a = '{}{}{}'.format(convert_number(h_c),
                            convert_number(m_c), 
                            convert_number(s_c))
    if len(set(a)) <= 2:
        total += 1

    return total

- Fernando May 24, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you post the same in js

- Mani July 02, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you post the same in js

- Mani July 02, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please post the same answer in javascript

- Abhishek Jain July 31, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please post the same answer in javascript

- Abhishek Jain July 31, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
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") )

- NoOne May 24, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

in one full hour we have 16 interesting times: two digits in four positions (2^4)
in one full minute we have 4 times 2^2, just need to count full hours, full minutes and take on partial hours and minutes

- Vadim May 24, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More