CI pipeline: order the stages for a safe deploy
Python data engineering interview problem. Difficulty: beginner. Pattern: Sorting. About 10 minutes. Free to practice.
A junior engineer wrote the CI (continuous integration) config for your project. CI is the automatic job that checks and ships your code. Their config runs the stages in this order: build, deploy, lint, test, verify. That means the code is deployed before it is tested, so a broken build can reach users.
Write a function safe_order(stages) that takes a list of stage names and returns the same stages in the safe order: lint, test, build, deploy, verify. Some stage names might not be in that list, such as 'notify'. Those stages go after all the known ones, and they keep the same order among themselves as in the input. Call your function on the junior engineer's list, ["build", "deploy", "lint", "test", "verify"], and print the result. Keep the print lines at the bottom of the editor, because the grader reads what your code prints.
Requirements
- Put the known stages in this order: lint, test, build, deploy, verify.
- Stages that are not in that list come after all the known stages.
- Unknown stages keep their original order relative to each other.
- Return a list. Do not change the input list.
Constraints
- stages is a list of strings. Some of them may not be in the safe order list.
- Known stages are sorted by their position in the safe order.
- The grader reads the text that your code prints, so keep the print lines.
Examples
Input: safe_order(["build", "deploy", "lint", "test", "verify"]) Output: ['lint', 'test', 'build', 'deploy', 'verify'] This is the expected return value for the given call.
Topics: ci-cd, infra, ordering.
More Python interview questions · All interview problems · Learn data engineering
CI pipeline: order the stages for a safe deploy
Production ticket: lint, then test, then build, then deploy, then verify - the order is the whole point.
A junior engineer's CI config runs stages in this order: `["build", "deploy", "lint", "test", "verify"]`. A deploy that runs before tests can ship a red build. Write `safe_order(stages)` that returns the stages re-ordered to: `lint`, `test`, `build`, `deploy`, `verify` - any stage not in that list keeps its relative position at the end. Call it on the junior engineer's list and print the result. Keep the prints at the bottom. The grader reads stdout.