CCA study materials
CCA study resources

CCA (CNCF) practice questions

One question at a time. Build your CCA understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Coding Knowledge and Skills

In SQL, which clause is used to filter individual rows before any grouping is performed?

  1. WHERE Correct answer.
  2. GROUP BY
  3. ORDER BY
  4. HAVING

Explanation

The WHERE clause evaluates a predicate against each row and removes rows that fail it before grouping or aggregation happens. HAVING is applied after grouping to filter groups, GROUP BY forms the groups, and ORDER BY only sorts the final result.

Question 2Coding Knowledge and Skills

A developer writes `if (x = 5)` in C where `x` is an int. What is the primary consequence of this statement?

  1. The program aborts at runtime with an undefined-behavior trap
  2. x is compared with 5 and the branch runs only when equal
  3. A compile error because assignment is not allowed in a condition
  4. The value 5 is assigned to x and the condition evaluates as true Correct answer.

Explanation

A single `=` is the assignment operator, so the expression stores 5 into x and then yields that value, which is nonzero and therefore true. Many compilers warn about this but still accept it, so the branch executes regardless of x's prior value.

Question 3Coding Knowledge and Skills

Which HTTP status code class indicates that the client's request was successfully received, understood, and accepted?

  1. 2xx Correct answer.
  2. 3xx
  3. 4xx
  4. 1xx

Explanation

The 2xx class signals successful processing of the request, such as 200 OK or 201 Created. The classes are grouped by first digit: informational, success, redirection, client error, and server error.

Question 4Coding Knowledge and Skills

In Git, which command creates a new commit that reverses the changes of a specific earlier commit without rewriting existing history?

  1. git reset --hard
  2. git checkout
  3. git revert Correct answer.
  4. git rebase

Explanation

`git revert` generates a new commit whose diff undoes the target commit, which is safe for shared branches because history is preserved. `git reset --hard` moves the branch pointer and discards work locally, and rebase rewrites commit ancestry.

Question 5Coding Knowledge and Skills

What is the time complexity of searching for a key in a balanced binary search tree containing n nodes?

  1. O(n)
  2. O(1)
  3. O(n log n)
  4. O(log n) Correct answer.

Explanation

A balanced BST keeps its height logarithmic in n, so each comparison discards roughly half the remaining subtree. A lookup therefore follows at most O(log n) nodes. Degenerate unbalanced trees can reach O(n), but balance is assumed here.

Question 6Coding Knowledge and Skills

Which Python data type is immutable and can therefore be used as a dictionary key?

  1. dict
  2. set
  3. list
  4. tuple Correct answer.

Explanation

A tuple is immutable and hashable when all its elements are hashable, so it qualifies as a dictionary key. Lists, dictionaries, and sets are mutable and therefore unhashable by default.

Question 7Coding Knowledge and Skills

In a relational database, what does a foreign key constraint enforce?

  1. That every value in the column is unique across the table
  2. That the column is automatically indexed with a clustered index
  3. That the column can never store a NULL value
  4. That each value in the column exists in a referenced key column Correct answer.

Explanation

A foreign key requires each non-null value in the referencing column to match a value in the referenced primary or unique key. This preserves referential integrity between related tables. Uniqueness and nullability are controlled by separate constraints.

Question 8Coding Knowledge and Skills

What does an object-oriented class method marked `static` mean in Java?

  1. It can only be called once during program startup
  2. It cannot access any other method in the class
  3. It is automatically synchronized across all threads
  4. It belongs to the class itself and is invoked without an instance Correct answer.

Explanation

A static method is associated with the class rather than with any object, so it is called through the class name and has no implicit `this` reference. It can still call other static members of the same class.

Question 9Coding Knowledge and Skills

A function takes an array of n integers and, for each element, scans the entire array once. What is the resulting time complexity?

  1. O(2^n)
  2. O(log n)
  3. O(n)
  4. O(n^2) Correct answer.

Explanation

The outer loop runs n times and each iteration performs a full n-element scan, giving n multiplied by n operations. Dominant-term analysis yields O(n^2) for this nested-loop pattern.

Question 10Coding Knowledge and Skills

In JavaScript, which statement about `let` and `var` declarations is accurate?

  1. `var` is block-scoped while `let` is function-scoped
  2. `let` is block-scoped while `var` is function-scoped Correct answer.
  3. Neither declaration is hoisted to any scope
  4. Both are function-scoped and hoisted identically

Explanation

`let` confines the binding to the enclosing block, whereas `var` binds to the nearest function or global scope. Both are hoisted, but `let` remains in a temporal dead zone until its declaration executes.

Question 11Coding Knowledge and Skills

Which SQL construct returns rows from the first query that are not present in the second query?

  1. UNION ALL
  2. CROSS JOIN
  3. EXCEPT Correct answer.
  4. INNER JOIN

Explanation

EXCEPT performs set difference, returning distinct rows from the left result that do not appear in the right result. INNER JOIN matches rows across tables, UNION ALL concatenates results, and CROSS JOIN produces a Cartesian product.

Question 12Coding Knowledge and Skills

A recursive function lacks a base case. What happens when it is called?

  1. It recurses until the call stack overflows Correct answer.
  2. It automatically memoizes repeated calls
  3. The compiler rejects it before execution
  4. It returns the default value for its return type

Explanation

Without a base case the recursion never terminates, so each call pushes a new frame until the stack limit is exceeded, producing a stack overflow. The compiler generally cannot detect this condition statically.

Question 13Coding Knowledge and Skills

What is the main purpose of a hash function in a hash table?

  1. To compress the stored values into fewer bytes
  2. To guarantee that no two keys ever collide
  3. To sort keys into ascending order for iteration
  4. To map a key to an index in the underlying bucket array Correct answer.

Explanation

A hash function converts a key into an integer that is reduced modulo the bucket count to select a slot. Because collisions are unavoidable for arbitrary key sets, the table must also resolve them, for example by chaining or open addressing.

Question 14Coding Knowledge and Skills

In a REST API, which HTTP method is expected to be idempotent and used to fully replace a resource representation?

  1. POST
  2. PATCH
  3. PUT Correct answer.
  4. CONNECT

Explanation

PUT replaces the target resource with the supplied representation and is idempotent, so repeating the same request yields the same state. POST is neither safe nor idempotent, and PATCH applies partial modifications.

Question 15Coding Knowledge and Skills

Which Git operation integrates changes from another branch by creating a new commit with two parents?

  1. git stash
  2. git cherry-pick
  3. git merge Correct answer.
  4. git fetch

Explanation

A merge combines the histories of two branches and, when a fast-forward is not possible, records a merge commit with two parent commits. Cherry-pick copies individual commits, fetch only downloads objects, and stash shelves local changes.

Question 16Coding Knowledge and Skills

What distinguishes a compiled language from an interpreted one at the point of execution?

  1. Compiled code is translated to machine code ahead of execution Correct answer.
  2. Interpreted languages are always dynamically typed
  3. Interpreted code cannot produce any output
  4. Compiled languages cannot use variables

Explanation

A compiler translates source into machine or intermediate code before the program runs, while an interpreter executes source statements directly. Many modern runtimes blend both approaches, but the ahead-of-time translation remains the defining distinction.

Question 17Coding Knowledge and Skills

In Python, what does a list comprehension such as `[x*2 for x in range(3)]` evaluate to?

  1. [0, 1, 2]
  2. [0, 2, 4] Correct answer.
  3. [1, 2, 3]
  4. [2, 4, 6]

Explanation

`range(3)` yields 0, 1, and 2, and each value is multiplied by 2, producing the list [0, 2, 4]. A comprehension builds a new list by applying the expression to every item of the iterable.

Question 18Coding Knowledge and Skills

Which design principle states that a class should have only one reason to change?

  1. Single responsibility principle Correct answer.
  2. Dependency inversion principle
  3. Liskov substitution principle
  4. Open-closed principle

Explanation

The single responsibility principle assigns each class one cohesive responsibility, so changes in unrelated areas of the system do not force edits to it. The other SOLID principles address extension, substitutability, and abstraction dependencies respectively.

Question 19Coding Knowledge and Skills

A developer needs to store a large collection of records and repeatedly check membership by unique identifier with average constant time. Which structure best fits?

  1. A stack
  2. A sorted array searched with binary search
  3. A singly linked list
  4. A hash set keyed on the identifier Correct answer.

Explanation

A hash set offers average O(1) membership tests by hashing each identifier to a bucket. Binary search on a sorted array is O(log n), while a linked list and a stack require linear scans for membership.

Question 20Coding Knowledge and Skills

Which situation indicates that a database index on a column is likely counterproductive?

  1. The column is a small table with heavy write traffic and rare reads Correct answer.
  2. The column is frequently used in equality filters
  3. The column has high cardinality
  4. The column is used in join predicates

Explanation

Every index adds write overhead because inserts, updates, and deletes must maintain it, so on a small, write-heavy table with few reads the maintenance cost can exceed any lookup benefit. High cardinality, join use, and frequent filters are all reasons an index helps.

Question 21Coding Knowledge and Skills

Consider a function that processes each element of an input list and stores results in a dictionary keyed by the element. If duplicate elements appear, what happens to the stored result?

  1. The duplicates are silently dropped without processing
  2. An exception is raised on the first duplicate
  3. The later result overwrites the earlier one for that key Correct answer.
  4. Each duplicate creates a separate dictionary entry

Explanation

Dictionary keys are unique, so assigning to an existing key replaces its previous value. The function still processes every element, but only the last result per distinct key survives in the dictionary.

Question 22Coding Knowledge and Skills

Two concurrent threads increment a shared integer without synchronization. What is the most likely defect?

  1. A lost update caused by a non-atomic read-modify-write Correct answer.
  2. A guaranteed deadlock on every execution
  3. A compile-time type mismatch
  4. Automatic serialization of both increments

Explanation

Incrementing involves reading, modifying, and writing the value, and interleaving these steps across threads can cause one update to overwrite the other. The result is a lost update or race condition, which may appear intermittently rather than on every run.

Question 23Coding Knowledge and Skills

A query filters on a column wrapped in a function, such as `WHERE UPPER(name) = 'ANA'`, and performs poorly despite an index on `name`. What is the best explanation?

  1. Equality comparisons cannot use indexes
  2. The function prevents normal index use, so a full scan occurs Correct answer.
  3. UPPER is not permitted in a WHERE clause
  4. The index is corrupt and must be rebuilt

Explanation

Applying a function to the indexed column makes the predicate non-sargable, so the optimizer generally cannot seek the index and falls back to scanning. Rewriting the predicate or creating an expression index restores index usage.

Question 24Coding Knowledge and Skills

A recursive algorithm solves a problem by splitting it into two halves and combining results in linear time. Which recurrence describes its running time?

  1. T(n) = 2T(n-1) + O(n)
  2. T(n) = 2T(n/2) + O(n) Correct answer.
  3. T(n) = T(n-1) + O(1)
  4. T(n) = T(n/2) + O(1)

Explanation

Two subproblems of half the size plus linear combination work is captured by T(n) = 2T(n/2) + O(n). By the master theorem this resolves to O(n log n), matching algorithms such as merge sort.

Question 25Coding Knowledge and Skills

A developer must choose between optimistic and pessimistic concurrency control for a system with frequent conflicting writes to the same rows. Which choice is better justified?

  1. Optimistic control, because it never blocks readers under any isolation level
  2. Optimistic control, because conflicts are frequent and retries are cheap
  3. Pessimistic control, because locking avoids repeated wasted work from collisions Correct answer.
  4. Pessimistic control, because it eliminates the need for transactions

Explanation

When conflicts are frequent, optimistic schemes repeatedly detect collisions and roll back, wasting work, whereas pessimistic locking serializes access up front. Optimistic control suits low-contention workloads where retries are rare.

Question 26Coding Knowledge and Skills

In a version control workflow, a developer wants to preserve a linear history while integrating a feature branch that contains many messy intermediate commits. Which command sequence best supports that goal?

  1. git merge --no-ff feature followed by git push
  2. git rebase -i feature followed by git checkout main and git merge feature Correct answer.
  3. git stash feature followed by git pull
  4. git revert feature followed by git commit

Explanation

Interactive rebase lets the developer squash, reword, or drop commits on the feature branch so the branch presents a clean set of changes. After rewriting history, merging into main with a fast-forward keeps the mainline linear. Plain merge preserves the messy commits, and revert or stash do not clean up the feature branch.

Question 27Coding Knowledge and Skills

A developer writes a unit test for a function that reads the current system clock. The test passes locally but fails intermittently on CI. Which refactoring most directly removes the flakiness?

  1. Increase the test timeout in the CI configuration
  2. Add a retry loop around the assertion
  3. Inject a clock or time provider as a parameter so the test can supply a fixed time Correct answer.
  4. Run the test only during business hours on the CI server

Explanation

Non-determinism from reading the real clock is best removed by making time an explicit dependency, which lets the test supply a fixed value and assert deterministically. Timeouts, retries, and scheduling tricks mask the symptom rather than eliminating the source of variability.

Question 28Coding Knowledge and Skills

Which statement correctly describes the role of a `finally` block in exception handling in languages such as Java and Python?

  1. It executes only when the try block completes without raising an exception
  2. It suppresses any exception raised inside the try block
  3. It executes only when an exception is caught by a matching handler
  4. It executes regardless of whether the try block completed normally or raised an exception Correct answer.

Explanation

A finally block is designed to run on every exit path from the try statement, whether normal completion, a caught exception, or an uncaught exception propagating outward. This makes it suitable for releasing resources such as file handles or locks. It does not swallow exceptions on its own.

Question 29Coding Knowledge and Skills

A service must expose an operation that creates a new order and must not create duplicates when a client retries after a network timeout. Which API design choice best addresses this requirement?

  1. Rely on the client to check for duplicates before sending
  2. Return HTTP 500 on every retry so clients stop resending
  3. Use HTTP GET with the order details in the query string
  4. Require an idempotency key sent by the client and deduplicate server-side Correct answer.

Explanation

Creation is not naturally idempotent, so a client-supplied idempotency key lets the server recognize a retried request and return the original result instead of creating a second order. This is a standard pattern for safe retries on non-idempotent operations. Client-side checks race with other clients and cannot be trusted.

Question 30Coding Knowledge and Skills

In Python, what does the expression `len({1, 2, 2, 3})` evaluate to?

  1. 3 Correct answer.
  2. A TypeError is raised
  3. 2
  4. 4

Explanation

A set literal stores unique elements, so the duplicate 2 collapses and the set contains three distinct values. `len` therefore returns 3. Sets are unordered but their cardinality reflects distinct membership.

Question 31Coding Knowledge and Skills

A developer needs a data structure that supports fast insertion and removal at both ends and does not require random access by index. Which choice best fits?

  1. A binary search tree keyed by insertion order
  2. A doubly linked list with head and tail references Correct answer.
  3. A singly linked list traversed only from the head
  4. A fixed-size array with shifting on removal

Explanation

A doubly linked list with references to both ends gives O(1) insertion and removal at the head and tail, which matches the requirement. Arrays require shifting elements, and a head-only singly linked list cannot remove the tail in constant time. A binary search tree does not target end operations.

Question 32Coding Knowledge and Skills

A code review flags a method that builds a SQL statement by concatenating user input directly. Which change most effectively prevents SQL injection?

  1. Logging every query for later inspection
  2. Escaping single quotes with a manual replace call
  3. Using parameterized queries with bound placeholders Correct answer.
  4. Limiting the input length to 32 characters

Explanation

Parameterized queries send the statement structure and the data separately, so user input cannot alter the parsed SQL. Manual escaping is error-prone and easy to bypass with encoding tricks. Length limits and logging do not change how the input is interpreted.

Question 33Coding Knowledge and Skills

A developer must choose between storing configuration in environment variables versus hardcoding values in source. Which statement best reflects accepted practice for a twelve-factor style application?

  1. Configuration should be read only at build time and never at runtime
  2. Configuration should be committed to the repository in a plaintext file for auditability
  3. Configuration should be stored in environment variables so the same build can run in different environments Correct answer.
  4. Configuration should be compiled into the artifact to guarantee reproducibility

Explanation

Separating configuration from code lets one build artifact be deployed across environments with different settings, which is a core principle of twelve-factor apps. Secrets and environment-specific values should not be baked into the artifact or committed in plaintext.

Question 34Coding Knowledge and Skills

A function is documented as pure. Which behavior is consistent with that contract?

  1. It reads a global random seed to vary its output
  2. It returns a new list built only from its arguments without modifying them Correct answer.
  3. It writes a log line to a file on every call
  4. It increments a module-level counter each time it is called

Explanation

A pure function depends only on its inputs and produces its result without side effects, so building and returning a new list from arguments qualifies. Mutating shared state, performing I/O, or depending on external mutable state breaks purity.

Question 35Coding Knowledge and Skills

A developer is designing a cache that must evict entries when full and wants to favor recently used items. Which eviction policy best matches that intent?

  1. Random replacement
  2. Last-in, first-out
  3. Least recently used Correct answer.
  4. First-in, first-out

Explanation

Least recently used eviction removes the item that has gone longest without access, which favors keeping recently used entries. FIFO ignores access recency, random replacement is unpredictable, and LIFO favors the newest entries rather than the most used.

Question 36Coding Knowledge and Skills

A developer writes a loop that appends to a string inside a hot path in a language where strings are immutable. Which change most improves performance?

  1. Wrap the string concatenation in a try block
  2. Increase the loop counter step size
  3. Move the concatenation into a separate function
  4. Append to a mutable buffer and convert to a string once at the end Correct answer.

Explanation

With immutable strings, each concatenation allocates a new value and copies prior content, producing quadratic work. Accumulating into a mutable buffer amortizes the copying and yields linear behavior. Wrapping in try, changing the step, or extracting a function does not change the allocation cost.

Question 37Coding Knowledge and Skills

Which statement best describes the difference between a stack trace and a log message when diagnosing a production failure?

  1. A log message always includes a stack trace in every logging framework
  2. A stack trace is only produced by compiled languages
  3. A log message is only useful when the program crashes
  4. A stack trace records the call path at the point of failure, while a log message records an event chosen by the developer Correct answer.

Explanation

A stack trace captures the sequence of active calls at the moment an error is raised, which helps locate the failing code path. A log message is an explicit record the developer chose to emit, which may or may not include a trace. Logs are useful for many events beyond crashes.

Question 38Coding Knowledge and Skills

A developer notices that a service's latency spikes every time a rarely used report endpoint is called, and the report endpoint holds a database connection for a long time. Which design change best isolates the impact?

  1. Increase the connection pool size for the whole service
  2. Give the report workload its own connection pool or database replica Correct answer.
  3. Add a retry loop to the report endpoint
  4. Lower the report endpoint's response timeout only

Explanation

Isolating a slow workload into a separate pool or replica prevents it from starving the interactive traffic that shares connections. Simply enlarging the shared pool raises contention and resource use, while retries and timeouts do not reduce the connection hold time.

Question 39Coding Knowledge and Skills

In a language with garbage collection, which situation most often causes a memory leak despite automatic collection?

  1. Local variables are declared inside a loop body
  2. Objects are allocated and then dropped out of scope
  3. The collector runs on a separate thread
  4. A long-lived collection retains references to objects that are no longer needed Correct answer.

Explanation

A reachability-based collector reclaims only unreachable objects, so a long-lived collection that keeps references alive prevents reclamation. That is the classic cause of leaks in managed languages. Dropped locals and loop-scoped variables become unreachable and are collected normally.

Question 40Coding Knowledge and Skills

A developer wants to parse a configuration file that uses indentation to express nesting. Which format is designed for that structure?

  1. Comma-separated values
  2. YAML Correct answer.
  3. INI without sections
  4. A fixed-width flat file

Explanation

YAML uses indentation to represent nested mappings and sequences, which makes it suitable for hierarchical configuration. CSV represents tabular rows, fixed-width files encode columns by position, and INI without sections cannot express nesting.

Question 41Coding Knowledge and Skills

A developer must implement a function that returns the first duplicate value in a list or reports that none exists. Which approach gives the best average-case time complexity?

  1. Recursively split the list and compare halves
  2. Sort the list and then scan adjacent pairs
  3. Iterate once while tracking seen values in a hash set Correct answer.
  4. Compare every pair of elements with nested loops

Explanation

A single pass with a hash set gives average O(n) time because membership checks are constant time on average. The nested-loop approach is quadratic, sorting costs O(n log n), and recursive halving without a shared set does not avoid repeated comparisons.

Question 42Coding Knowledge and Skills

A developer is reviewing a pull request that adds a new public function. Which practice best supports long-term maintainability of the codebase?

  1. Marking the function as deprecated from the start
  2. Avoiding tests to keep the pull request small
  3. Keeping the function undocumented so it can change freely
  4. Documenting the function's contract and adding tests for its edge cases Correct answer.

Explanation

A clear contract plus tests for edge cases makes the function's behavior explicit and guards against regressions. Undocumented or untested code is harder to change safely, and deprecating a new function immediately is not a maintainability strategy.

Question 43Coding Knowledge and Skills

A developer needs to expose a nested object over an API but wants to avoid sending fields the client does not need. Which technique best addresses over-fetching?

  1. Compress the response with gzip
  2. Add a version prefix to every endpoint
  3. Allow the client to request specific fields in the query Correct answer.
  4. Return the full object graph on every request

Explanation

Field selection lets clients ask for exactly the fields they need, reducing payload size and over-fetching. Returning the full graph always sends unnecessary data, compression reduces bytes but not the amount of data selected, and versioning addresses compatibility rather than payload shape.

Question 44Coding Knowledge and Skills

A developer writes a regular expression to validate a date in the form YYYY-MM-DD and wants to reject values such as 2023-13-45. Which limitation of the pattern-based approach is most relevant?

  1. A regular expression can check format but validating real calendar ranges is complex and error-prone Correct answer.
  2. Regular expressions always run in constant time
  3. A regular expression cannot be anchored to the start of a string
  4. Regular expressions cannot match digits

Explanation

Patterns can enforce the shape of a date, but validating month lengths, leap years, and day ranges grows intricate and is better handled by a date library. Regular expressions do match digits, can be anchored, and may exhibit backtracking costs on adversarial input.

Question 45Coding Knowledge and Skills

A developer must ensure that a background job does not run twice when two scheduler instances are active. Which mechanism best provides mutual exclusion across instances?

  1. A boolean flag in the job's configuration file
  2. A local lock object inside the job process
  3. A thread-local variable checked at job start
  4. A distributed lock stored in a shared system such as a database or coordination service Correct answer.

Explanation

Mutual exclusion across separate processes requires a shared, atomic coordination point, such as a distributed lock with a lease or a database row lock. In-process locks and thread-local variables only coordinate within one process, and a configuration flag is not an atomic guard.

Question 46Coding Knowledge and Skills

Which change best reduces the risk of a breaking change in a widely consumed library function?

  1. Renaming the function in a patch release
  2. Adding an optional parameter with a default while keeping existing behavior Correct answer.
  3. Changing the function's parameter order without notice
  4. Removing the function because a newer one exists

Explanation

Adding an optional parameter with a default preserves existing call sites and behavior, so consumers are unaffected. Reordering parameters, removing functions, or renaming in a patch release breaks callers and violates semantic versioning expectations.

Question 47Coding Knowledge and Skills

A developer wants to compare two large files line by line and produce a summary of additions and removals. Which approach is most appropriate?

  1. Compare the files byte by byte and count differences
  2. Compute a longest common subsequence between the line sequences Correct answer.
  3. Hash each file and compare the digests
  4. Sort the lines of each file and count total lines

Explanation

A line-oriented diff is built on a longest common subsequence or similar alignment, which identifies which lines were added or removed while preserving order. Byte comparison gives no line-level summary, hashing only reports equality, and sorting loses the original order needed to describe changes.

Question 48Coding Knowledge and Skills

A developer is choosing between a synchronous and an asynchronous call for a long-running image processing step in a web request. Which choice best avoids tying up request threads?

  1. Call the processing synchronously and raise the request timeout
  2. Process the image twice to average the result
  3. Reduce the image size until processing is instant
  4. Enqueue the work and return a job identifier the client can poll Correct answer.

Explanation

Moving long-running work to a queue frees the request thread and returns quickly with a job identifier, which the client can poll for completion. Synchronous processing consumes a request thread for the whole duration, and the other options do not address thread occupancy.

Question 49Coding Knowledge and Skills

A developer wants a function to accept either a single value or a list of values without duplicating logic. Which approach best expresses this in a dynamically typed language?

  1. Require callers to always pass a list and reject single values
  2. Normalize the argument into a list at the top of the function and process uniformly Correct answer.
  3. Use a global variable to signal which form was passed
  4. Write two separate public functions with different names

Explanation

Normalizing the input at the boundary lets the core logic handle a single uniform shape, which removes duplication and keeps behavior consistent. Separate functions duplicate logic, rejecting single values burdens callers, and a global flag introduces hidden coupling.

Question 50Coding Knowledge and Skills

A developer is debugging a program that produces different output on each run even though the input is identical. Which cause is most likely?

  1. The program depends on unordered iteration over a hash-based collection Correct answer.
  2. The program defines local variables inside a function
  3. The program uses integer arithmetic
  4. The program reads its input from a file

Explanation

Iteration order over some hash-based collections can vary between runs or processes, so any logic that depends on that order produces non-deterministic output. Integer arithmetic, file input, and local variables are deterministic given the same input.