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