Solve common array/graph interview problems
Company: Art Advisors
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
You are given several independent coding tasks. Implement each function according to the specification below.
## 1) Rotate a square matrix in-place
**Input:** An integer matrix `M` of size `n x n`.
**Task:** Rotate the matrix **90 degrees clockwise** **in-place** (modify `M` directly).
**Constraints:**
- `1 <= n <= 500`
- Aim for `O(n^2)` time and `O(1)` extra space.
**Example:**
- Input:
```
[[1,2,3],
[4,5,6],
[7,8,9]]
```
- Output:
```
[[7,4,1],
[8,5,2],
[9,6,3]]
```
---
## 2) Shortest word transformation steps
**Input:**
- `begin`: a lowercase word
- `end`: a lowercase word
- `words`: a list of lowercase words (dictionary)
**Task:** Return the length of the shortest sequence of transformations from `begin` to `end`, where:
- Each step changes **exactly one character**.
- Every intermediate word must exist in `words`.
- If no sequence exists, return `0`.
**Constraints:**
- All words have the same length `L`.
- `1 <= |words| <= 50_000`, `1 <= L <= 10`.
**Example:**
- `begin = "hit"`, `end = "cog"`, `words = ["hot","dot","dog","lot","log","cog"]`
- Output: `5` (e.g., `hit -> hot -> dot -> dog -> cog`)
---
## 3) Compute the H-index
A researcher’s H-index is defined as the maximum integer `h` such that the researcher has **at least `h` papers** with **at least `h` citations each**.
**Input:** An array `citations` where `citations[i]` is the number of citations for paper `i`.
**Task:** Return the researcher’s H-index.
**Constraints:**
- `0 <= n <= 200_000`
- `0 <= citations[i] <= 1_000_000_000`
- Prefer `O(n)` or `O(n log n)` time.
**Example:**
- Input: `[3,0,6,1,5]`
- Output: `3` (three papers have at least 3 citations)
Quick Answer: This multi-part question evaluates proficiency in array and matrix manipulation, graph traversal and shortest-path reasoning for word transformations, and algorithmic counting/selection for computing metrics like the H-index.