Katkat

Solve mixed coding tasks from interviews

AppleSoftware Engineer · Technical Screen

Last 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.

  1. 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).

  2. 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 as YYYYMMDD. You only need to describe the algorithm (no code required), but be precise about leap years and month lengths.

  3. 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 array edge[0..n-1] where edge[i]=1 iff x[i-1]=0 and x[i]=1 (assume edge[0]=0).

  4. 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).