13 real SenseTime interview questions with full model answers — Behavioral, Coding, Technical. Drawn from the same verified bank ChannelPulse drills from (13 SenseTime questions in total).
1. Have you read the source code of any large Python project?
Model answer
Situation — Yes. One substantial Python codebase I studied was Django, because I was working with a service that used its ORM and I wanted to understand behavior that the public API alone did not explain. I focused on how a model declaration becomes a query and how that query is eventually executed, rather than trying to read the whole repository linearly.
Task — My goal was to debug ORM behavior confidently and make informed choices about query performance, while keeping the investigation small enough to fit alongside feature work.
Action
I started from a concrete example in our code: a related-object lookup that appeared to issue more database queries than expected. I reproduced it in a small test and checked the documented behavior first.
Then I traced the relevant path through Django’s source: model construction and field metadata, the manager and QuerySet, query compilation, and the database backend. I used targeted searches and debugger breakpoints rather than reading entire modules without a question.
I read the tests alongside the implementation. They clarified edge cases around lazy evaluation and related-object loading, and showed which behaviors Django treats as stable contracts.
I compared the query counts for the original code and a version using select_related for the single-valued relation. I also checked that the optimization did not change returned results, because query-count reductions are not useful if semantics change.
I shared the trace with teammates in a short code review note, including which operations evaluate a QuerySet and when to use select_related versus prefetch_related.
Result — We fixed the unnecessary queries on that path and added a query-count regression test, so the behavior stayed visible during later changes. More importantly, I could explain the performance issue from the framework’s execution path instead of relying on guesswork. I learned to approach large source trees with a specific observed behavior, follow the call path, and use tests to distinguish implementation details from supported guarantees.
2. Which part of your previous work and internships were you most interested in?
Model answer
Situation — The work I was most interested in was an end-to-end computer-vision project during an internship: building a model to recognize objects in images captured under varied lighting and camera conditions. I was especially drawn to it because performance mattered not only in a benchmark, but also in whether the system behaved reliably on real data.
Task — I owned a substantial part of the model-development loop, from preparing data and establishing a baseline to evaluating improvements. The main tension was improving accuracy without making the model too slow or fragile for deployment.
Action
I first audited the data and evaluation setup, checking label quality and breaking results down by conditions such as lighting and object size. That showed me that a single aggregate metric could hide important failure cases.
I built a reproducible baseline and used targeted error analysis to decide what to try next, rather than changing the architecture based only on intuition.
I compared augmentation and model-training choices on the same validation protocol, tracking both accuracy and inference cost. For example, I investigated whether harder lighting examples were being missed and tested augmentations that represented those conditions.
I shared the failure analysis with the team and used it to prioritize experiments, so data and model changes could be discussed against the same evidence.
I also documented the evaluation steps and results so another engineer could reproduce the comparison.
Result — The work improved the model’s validation performance on the difficult conditions we had identified, while keeping inference requirements in view. More importantly, it changed how I think about machine learning: the part I find most engaging is connecting data, modeling, evaluation, and deployment, not optimizing a metric in isolation. That is why applied vision work at SenseTime particularly interests me.
3. There are n street lights numbered 1 through n, all initially off.
The full question
There are n street lights numbered 1 through n, all initially off. Perform n operations: in operation i, toggle every light whose number is a multiple of i. How many lights are on after all operations?
Model answer
function countLightsOn(n) {
// Only perfect squares have an odd number of divisors.
return Math.floor(Math.sqrt(n));
}
console.log(countLightsOn(10)); // 3: lights 1, 4, and 9
Light k is toggled once for each divisor of k.
Divisors normally pair up; only a perfect square has an unpaired divisor, so it is toggled an odd number of times and ends on.
4. Given n ≤ 20, values aᵢ < 100, and an integer s, how many assignments of positive and negative signs to the aᵢ values make their signed sum equal s?
Model answer
function countSignAssignments(a, s) {
// Map each reachable signed sum to the number of assignments producing it.
let ways = new Map([[0, 1]]);
for (const value of a) {
const next = new Map();
for (const [sum, count] of ways) {
const plusSum = sum + value;
const minusSum = sum - value;
next.set(plusSum, (next.get(plusSum) || 0) + count);
next.set(minusSum, (next.get(minusSum) || 0) + count);
}
ways = next;
}
return ways.get(s) || 0;
}
// Example: +1 + 2 + 3 = 6, and -1 - 2 + 3 = 0.
console.log(countSignAssignments([1, 2, 3], 0)); // 2
After processing each value, keep the count of ways to reach every possible sum by assigning it either + or -.
Equal values and zero values are handled correctly: assignments are counted by position, not by distinct resulting sums.
Complexity: Let R = Σ|aᵢ|. Time is O(nR) and space is O(R) in the bounded-sum setting.
5. Given a 0/1 string, find the length of the longest substring containing the same number of 0s and 1s.
The full question
Given a 0/1 string, find the length of the longest substring containing the same number of 0s and 1s. For example, in "00100110011", the longest such substring has length 10.
Model answer
function longestBalancedBinarySubstring(s) {
// Map each prefix balance to its earliest index.
// Treat 0 as -1 and 1 as +1; equal balances enclose a balanced substring.
const firstIndex = new Map([[0, -1]]);
let balance = 0;
let longest = 0;
for (let i = 0; i < s.length; i++) {
balance += s[i] === "0" ? -1 : 1;
if (firstIndex.has(balance)) {
longest = Math.max(longest, i - firstIndex.get(balance));
} else {
firstIndex.set(balance, i);
}
}
return longest;
}
console.log(longestBalancedBinarySubstring("00100110011")); // 10
Convert each 0 and 1 to opposite contributions; a substring is balanced when its prefix balances match.
Keep the earliest index for each balance to maximize the substring length.
Loop unrolling is a compiler optimization that replicates a loop body to reduce loop-control overhead and expose more instruction-level parallelism.
For example, a loop that adds one element per iteration can be unrolled by a factor of four to process four elements per iteration, followed by a cleanup loop for any remaining elements:
function sum(values) {
let total = 0;
let i = 0;
// Process four elements per iteration.
for (; i + 3 < values.length; i += 4) {
total += values[i];
total += values[i + 1];
total += values[i + 2];
total += values[i + 3];
}
// Handle the remainder.
for (; i < values.length; i++) {
total += values[i];
}
return total;
}
Potential benefit: Fewer branches and index updates; the CPU may execute independent operations in parallel or vectorize them.
Costs: Larger code size, potentially worse instruction-cache behavior, and more complicated handling of remainders. It can also hurt performance if the loop is already cheap or the compiler cannot safely prove the transformation preserves behavior.
Practical point: Compilers often perform unrolling automatically based on optimization settings and target architecture. Benchmark representative workloads rather than assuming manual unrolling is faster.
7. How are Django's framework and model implemented?
Model answer
Django is a Python web framework organized around request/response handling and reusable components. Its ORM model system is part of that framework: model classes describe data and Django turns their metadata and queries into database operations.
flowchart LR
A[HTTP request] --> B[URL resolver]
B --> C[Middleware]
C --> D[View]
D --> E[Model and QuerySet]
E --> F[SQL compiler]
F --> G[Database backend]
G --> E
E --> D
D --> H[Template or response]
H --> C
C --> I[HTTP response]
Diagram
Request framework: Django's WSGI or ASGI handler creates a request object and runs middleware. The URL resolver matches the path to a view; the view calls application logic and returns an HttpResponse. Middleware can process requests and responses around that view. Templates are one rendering option, not a required part of every request.
Application setup:django.setup() loads settings and populates the app registry. Apps register models and other components, making model metadata available to the ORM and migration system.
Model class construction: A class such as class Item(models.Model) is processed by Django's ModelBase metaclass. It gathers declared fields and options, builds _meta metadata, contributes descriptors to the class, and installs managers. Fields define database and Python-level behavior; descriptors mediate attribute access and related-object access.
Query construction and execution: A manager returns a QuerySet. QuerySets are generally lazy: filtering and ordering build a query description, while iteration, evaluation, or similar operations trigger execution. The ORM converts that description through its SQL compiler and database backend, then maps rows back to model instances. save() and related operations issue writes; they are not a substitute for explicit transaction design.
Schema management: Models describe the intended schema. makemigrations compares model state with migration state and generates migration operations; migrate applies them through the configured database backend. This keeps schema changes reviewable and deployable.
The important design idea is separation of concerns: views coordinate request behavior, models and QuerySets express data operations, and backend-specific code handles SQL differences. That makes common application code portable while still allowing explicit SQL or database-specific features when needed.
8. What happens from the time you type a command into the shell until the program executes?
Model answer
The shell reads and parses the command. After you press Enter, the shell tokenizes the input, handles quoting and operators such as pipes or redirection, and performs expansions such as variables, wildcards, and command substitution. It checks whether the command is a shell builtin; a builtin can run inside the shell process without starting an external program.
For an external command, the shell locates the executable. A command containing a path is resolved directly; otherwise, the shell searches directories in PATH. It checks that the file can be executed and prepares the argument list and environment.
The shell creates a process and executes the program. Typically, it calls fork() (or an equivalent process-creation mechanism). The child sets up any requested input/output redirection and then calls execve(). execve() replaces the child’s program image with the requested executable. For a foreground command, the parent shell waits; for a background command, it returns to the prompt.
The kernel loads the executable. The kernel validates the executable format, maps its code and data into the process’s virtual address space, and sets up the initial stack with arguments and environment variables. For a dynamically linked program, the dynamic linker loads shared libraries and resolves symbols before control reaches the program’s entry point and eventually its main() function.
The program runs and the shell resumes. The scheduler gives the process CPU time. The program makes system calls when it needs kernel services such as file or network I/O. When it exits, the kernel records its exit status and notifies the waiting shell, which updates $? and displays the next prompt.
flowchart TD
A[Enter command] --> B[Shell parses and expands]
B --> C{Builtin command?}
C -- Yes --> D[Shell runs builtin]
C -- No --> E[Resolve executable using PATH]
E --> F[Create child process]
F --> G[Set up redirection and pipes]
G --> H[execve loads program]
H --> I[Dynamic linker loads libraries]
I --> J[Program runs and makes syscalls]
J --> K[Process exits]
K --> L[Shell collects status and prompts]
D --> L
9. How does Python execute a program, from beginning to end?
Model answer
For CPython, execution is best understood as a pipeline from source text to bytecode to runtime behavior. Other Python implementations may use different execution strategies.
flowchart TD
A[Source file] --> B[Read and decode]
B --> C[Tokenize and parse]
C --> D[AST]
D --> E[Compile to code objects]
E --> F[Create module namespace]
F --> G[Execute bytecode]
G --> H{More instructions?}
H -- Yes --> G
H -- No --> I[Return or finish]
G --> J[Imports and runtime calls]
J --> G
G --> K[Exception or exit]
Diagram
Load source: Python reads the file, decodes it, and tokenizes the text into language tokens.
Parse and compile: The parser builds an abstract syntax tree (AST). The compiler checks and transforms it into code objects containing bytecode, constants, and metadata such as variable names. CPython may cache compiled bytecode in __pycache__ when applicable.
Initialize the module: The runtime creates a module object and its global namespace, then executes the module-level code. Definitions such as functions and classes create objects and bind names; their bodies generally run only when called.
Run bytecode: CPython's evaluation loop processes instructions in frames. Function calls create frames with local state; operations such as arithmetic can invoke Python methods or built-in implementations.
Resolve imports and services: An import consults sys.modules, then finders and loaders if needed. Imported module code is executed and its module object cached. Native extensions can call compiled code.
Handle completion: A normal return or end of module finishes execution. Exceptions unwind frames until handled or reported. Reference counting plus cyclic garbage collection manage object lifetimes; the interpreter and process then shut down.
The key distinction is that Python is commonly described as interpreted, but CPython first compiles source to bytecode and then executes that bytecode in its virtual machine.
10. What are the steps in compilation, and what happens at each step?
Model answer
Compilation transforms source code into an executable form through several stages. Exact names and ordering vary by language and toolchain, but a typical native-code pipeline is:
flowchart LR
A[Source] --> B[Preprocessing]
B --> C[Lexing and parsing]
C --> D[Semantic analysis]
D --> E[Intermediate representation]
E --> F[Optimization]
F --> G[Code generation]
G --> H[Assembly and object files]
H --> I[Linking]
I --> J[Executable]
Diagram
Preprocessing: Expands macros and includes, and handles conditional compilation where the language has a preprocessor, as in C and C++.
Lexing and parsing: The lexer converts characters into tokens; the parser checks grammar and builds a syntax tree.
Semantic analysis: Checks meaning: types, declarations, scopes, and valid operations. It reports errors that are syntactically valid but semantically invalid.
Intermediate representation (IR): Converts the program into a representation that is easier to analyze and optimize, often independent of the target CPU.
Optimization: Applies transformations such as constant folding, dead-code elimination, inlining, and loop optimizations, while preserving the program's defined behavior.
Code generation and assembly: Produces target-specific instructions, then assembles them into object files containing machine code and metadata.
Linking: Combines object files and libraries, resolves symbols, and produces an executable or shared library. Loading and dynamic linking may happen later at runtime.
Some languages use different pipelines. For example, CPython compiles Python source to bytecode, which its virtual machine executes; implementations such as PyPy may also use a JIT to generate machine code at runtime.
In CPython, a module's global variables live in its module namespace, which is a dictionary usually exposed as module.__dict__. A function retains a reference to the global namespace in which it was defined, so calling the function looks up globals in that namespace—not in the caller's module.
When a function reads a name, CPython first checks whether it is a local or free variable based on compile-time scope analysis. A name classified as global is looked up in the function's global namespace; if it is absent there, lookup falls back to the built-in namespace.
In CPython bytecode, global reads use LOAD_GLOBAL. Modern versions can specialize and cache this lookup, but the observable behavior remains dictionary-based lookup with built-ins as a fallback.
An assignment inside a function makes a name local by default throughout that function. Reading it before assignment raises UnboundLocalError. Use global name to make assignments target the module global; use nonlocal name for a binding in an enclosing function scope.
Mutating a global object is different from rebinding its name: items.append(x) can mutate a referenced global list without global items, while items = [] inside a function creates a local binding unless declared global.
count = 1
def read_count():
return count # Global lookup, then built-ins if missing.
def increment():
global count
count += 1
A useful performance implication is that repeated global lookups can cost more than local-variable access, though CPython's adaptive interpreter may optimize common lookups. Correctness and clear scope should guide code structure, not micro-optimization.
A process is a running program together with its execution state and resources: a virtual address space, registers, open handles, security context, and one or more threads.
On Unix-like systems, a common creation path is:
flowchart TD
A[Parent process] -->|fork or posix_spawn| B[Child process]
B -->|exec loads program| C[New program image]
C -->|initialize runtime| D[Program entry point]
A -->|wait or continue| E[Parent continues]
D -->|exit status| E
Diagram
With fork(), the child initially gets a logical copy of the parent's address space, commonly implemented efficiently with copy-on-write. It also inherits selected file descriptors and other process attributes.
The child often calls exec(), which replaces its address space with the requested executable, loads its code and data, sets up the stack and arguments, and transfers control to its entry point. exec() does not create another process; it replaces the current process image.
The OS assigns a process ID, establishes resource and security limits, and schedules the process when it is ready. The parent may wait for its exit status or run concurrently.
On Windows, CreateProcess generally creates the process and its initial thread and loads the executable as one operation.
In containerized ML services, process creation still relies on OS mechanisms, but namespaces and cgroups can further isolate processes and limit CPU, memory, and other resources.
13. What is the difference in behavior between [lambda x: x + i for i in range(4)] and def func1(i): return lambda x: x + i; [func1(i) for i in range(4)]?
Model answer
Both expressions create four lambdas, but the closures capture i differently.
funcs_a = [lambda x: x + i for i in range(4)]
funcs_b = [func1(i) for i in range(4)]
# The first list's lambdas all refer to the same captured i.
print([f(0) for f in funcs_a]) # [3, 3, 3, 3]
# Each func1 call creates a separate closure with its own i.
print([f(0) for f in funcs_b]) # [0, 1, 2, 3]
In the list comprehension, each lambda closes over the comprehension's i binding. The lambdas are called after the loop has finished, so they all see its final value, 3. This is late binding: the closure looks up the variable when called, rather than storing its value when created.
In the second expression, each call to func1(i) creates a new function scope. Its returned lambda closes over that invocation's local i, so each lambda retains a different value.
A common alternative is to bind the current value as a default argument: [lambda x, i=i: x + i for i in range(4)]. Default arguments are evaluated when each lambda is created.
Practice these out loud, don't memorise them
Reading an answer is not the same as being able to give one under pressure. ChannelPulse plays the interviewer, asks the follow-ups, and scores each answer with feedback and a model answer so you can hear the gap between what you said and what lands.