Find kth smallest and count stair-climbing ways
Company: Nio
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This pair evaluates proficiency with order-statistics and selection algorithms for finding the k-th smallest element and with dynamic programming and combinatorial recurrence reasoning for the staircase counting problem.
K-th Smallest Element without Sorting
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([3,1,2,2], 2)
Expected Output: 2
Explanation: Duplicates count.
Input: ([7], 1)
Expected Output: 7
Explanation: Single element.
Input: ([-1,5,0], 2)
Expected Output: 0
Explanation: Negative values.
Hints
- Model object-style prompts as arrays or operation streams when needed.
- Handle empty and boundary cases before the main logic.
Count Stair-Climbing Ways with 1 to 3 Steps
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (10,)
Expected Output: 274
Explanation: Prompt asks n=10.
Input: (0,)
Expected Output: 1
Explanation: One empty way.
Input: (3,)
Expected Output: 4
Explanation: 1+1+1,1+2,2+1,3.
Hints
- Model object-style prompts as arrays or operation streams when needed.
- Handle empty and boundary cases before the main logic.