This time, I'm going to share a set of the newest ones that came out on October 6 OpenAI OA real questions, appearing on the HackerRank platform. There are two programming questions in the whole OA, the overall difficulty is between Medium ~ Hard, the first question is path optimization on tree, the second question is biased towards graph search + state compression.
Question 1: Optimal Path
Title Description
A distributed system of servers is represented as a tree with tree_nodes nodes, numbered from 1 to tree_nodes. Moving between directly connected servers takes 1 unit of time.
A process needs to.
- Start at the
start_nodeserver. - Complete tasks at servers listed in an array
task_nodes[]of sizenum_tasks(by visiting them in any order). - End at the
end_nodeserver.
Find the minimum time required to complete all tasks and reach end_node.
Edges are bidirectional.
Constraints.
2 ≤ tree_nodes ≤ 2×10^5
1 ≤ num_tasks ≤ tree_nodes
1 ≤ start_node, end_node, task_nodes[i] ≤ tree_nodes
Example Inputs and Outputs
tree_nodes = 5
tree_from = [3, 2, 4, 1]
tree_to = [2, 5, 3, 2]
start_node = 1
end_node = 5
start_node = 1 end_node = 5 task_nodes = [4, 2]
Output:
6
Explanation:
The optimal path is 2 -> 3 -> 1(which under the tree mapping is equivalent to returning to the main path after visiting a task node).
A total of 6 units of time were spent.
Explanation of Ideas
This problem is a combination of "shortest path in tree + shortest set of necessary points".
The key idea is:
- The task nodes are in arbitrary order, so you can start by finding the set of necessary nodes that need to be accessed.
- These nodes include:
- All task_nodes
- start_node and end_node
- and their nodes on the least common ancestor path in the tree
Then we just need to compute the minimum connected subtree covered by these nodes in the tree (also known as the "Steiner Tree"), the
Then use DFS or BFS to find the total path length.
Key findings
The shortest path length to visit all the task nodes in the tree and go from the start point to the end point is:
2 * (sum of edges in minimal subtree) - distance(start_node, end_node)
The explanation is as follows:
- Each edge needs to be traveled through twice (go + back), but that part of the start → end path does not need to be turned back;
- So subtract the distance from start to end once.
Question 2: Minimum Operations to Reach Target
Title Description
You are given a starting integer start, a target integer target, and an integer array operations[].
In each step, you can move from your current position X to (x + op) % 100000, where op is any element from the array operations.
Return the minimum number of operations required to reach target From start.
If it is impossible to reach target, return -1.
Example
start = 3
target = 30
operations = [2, 5, 7]
Output:
6
Explanation:
An optimal path is:
3 → 5 → 10 → 15 → 22 → 24 → 30
Total 6 steps.
Deconstructing Ideas
This question looks simple, but it is a typical BFS state search on a graph.
Each number (0 to 999999) is viewed as a node, the
slave node X This can be done by adding any op(and then modulo 100000) jumps to a new node.
The goal is to start with start until (a time) target Minimum number of steps --
Unprivileged graph shortest path → BFS template questions.
OpenAI OA Difficulty Summary
| title number | typology | difficulty | exam point |
|---|---|---|---|
| Q1 | Optimal Path on Tree (Optimal Path) | Hard | Tree, least-subtree, path optimization |
| Q2 | Graph State Search (Modulo Graph BFS) | Medium | BFS, modulo arithmetic, graph traversal |
Recently, we at Programhelp have successfully helped many students pass the OpenAI OA and other large companies' written exams.
Unlike regular brushing, we offer a real-world level remote assisting experience:
- No Trace Online Assists: Real-time online in HackerRank / Codility / Codesignal to ensure that the code logic and test cases all pass;
- Algorithmic thought process: Do Mock training in advance for question types (e.g., path optimization on trees, statechart BFS) so that you don't panic during the exam;
- Real-time voice alerts: Instant prompts for key ideas when you get stuck on a question, allowing you to output efficiently in a time-limited environment;
If you are also preparing for OpenAI, Anthropic, DeepMind or other top tech companies OA / Interview.
Programhelp 's remote assisting service can help you to secure the written test and interview of the big companies, so that you are no longer alone.