Solve mixed coding tasks from interviews
AppleSoftware Engineer · Technical ScreenLast updated
This question evaluates binary tree traversal and leaf detection, calendrical date arithmetic and palindrome checking, discrete-time edge-detection/stateful sequence processing, and implementation of comparison-based sorting; category/domain: Coding & Algorithms. It is commonly asked to assess correctness and edge-case handling (e.g.
Solve the following interview-style coding problems (you may choose any programming language unless specified). Provide correct logic and handle edge cases.
-
Binary tree leaves: Given the root of a binary tree, output the values of all leaf nodes (nodes with no children). Specify the traversal order you choose (e.g., left-to-right).
-
Previous palindrome date: Given a date (e.g.,
YYYY-MM-DD), find the most recent earlier date (strictly before the given date) whose representation is a palindrome when written asYYYYMMDD. You only need to describe the algorithm (no code required), but be precise about leap years and month lengths. -
Edge detector: Implement a rising-edge detector for a boolean signal sampled on clock cycles. Given an array
x[0..n-1]of 0/1 samples, output an arrayedge[0..n-1]whereedge[i]=1iffx[i-1]=0andx[i]=1(assumeedge[0]=0). -
Sorting: Implement a sorting function for an array of integers (any correct O(n log n) sort is fine; if you choose bubble sort, state its complexity).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.