Level: Mid-Level
Round: Phone Screen · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Recursion, Iteration, Time Conversion
Location: Los Gatos, CA
Interview date: 2025-05-06
Got offer: False
Question: I was asked to implement a function that converts a given number of seconds into a human-readable time format (months, weeks, days, hours, minutes, seconds) using recursion.
The question I got was:
Implement a function timer that takes a single argument seconds (integer representing the number of seconds). The function returns a string representing the time in a human-readable form up to Months (assuming 30 days in a month).
Examples:
timer(55); // returns: 55 seconds timer(65); // returns: 1 minutes, 5 seconds timer(3805000); // returns: 1 months, 2 weeks, 56 minutes, 40 seconds
Requirements:
I initially implemented an iterative solution, which took considerable time because of the modulo operations for months, weeks, days, hours, minutes, and seconds. I was then asked to rewrite it using recursion. I found the recursive approach awkward and struggled to complete it in time. I didn't get to run the code, and I failed the interview.