Given an array of integers (0 to 9), rearrange the positions of the array elements to represent the second largest possible number.
Example 1:
Input: [1, 2, 3, 4, 5]
Output: [5, 4, 3, 1, 2]
Largest number: [5, 4, 3, 2, 1] (e.g. "54321")
Second largest: [5, 4, 3, 1, 2] (e.g. "54312")
Example 2:
Input: [1, 1, 2, 3, 4]
Largest number: [4, 3, 2, 1, 1]
Second largest: [4, 3, 1, 2, 1]
Given a binary tree, imagine yourself standing on the left side of it. Return the values of the nodes you can see ordered from bottom to top. Then switch to the right side of the tree, and return the values of the nodes you can see ordered from top to bottom.
Example:
Binary Tree:
1
/ \
2 3
/ \ /
6 5 4
Answer: [6, 2, 1, 3, 4]
These questions combine two classic interview themes: permutation construction and binary tree view traversal. The first problem asks for the second-largest arrangement of digits, which is essentially a lexicographic permutation task: build the largest ordering, then perform the smallest possible swap near the right side to create the next smaller valid permutation. The second problem asks for visible nodes from the left and right side of a binary tree, which is typically solved with level-order traversal or DFS by tracking the first/last node seen at each depth.