Mettl Coding Skills 3 ā Questions and Answers
Question 1: Which of the following correctly describes a hash collision?
- Two keys map to different hash values
- Two different keys produce the same hash value (Correct answer)
- A key maps to a null value
- The hash table is completely full
Correct answer: Two different keys produce the same hash value
A collision occurs when two distinct keys hash to the same index in the table.
Question 2: What is the worst-case space complexity of recursive quicksort due to call stack usage?
- O(1)
- O(log n)
- O(n) (Correct answer)
- O(n²)
Correct answer: O(n)
In the worst case (already sorted input), quicksort recurses n times, using O(n) stack space.
Question 3: In Java, which keyword prevents a method from being overridden in a subclass?
- static
- abstract
- final (Correct answer)
- private
Correct answer: final
Declaring a method 'final' prevents subclasses from overriding it.
Question 4: What does a REST API use to indicate that a resource was successfully created?
- HTTP 200 OK
- HTTP 201 Created (Correct answer)
- HTTP 204 No Content
- HTTP 301 Moved Permanently
Correct answer: HTTP 201 Created
HTTP 201 Created is the standard response for a successful POST that creates a new resource.
Question 5: Which of the following is NOT a valid way to declare a variable in JavaScript (ES6+)?
- let x = 5;
- const x = 5;
- var x = 5;
- def x = 5; (Correct answer)
Correct answer: def x = 5;
'def' is used in Python, not JavaScript; valid JS declarations use var, let, or const.
Question 6: What is memoization primarily used for in programming?
- Encrypting sensitive data
- Caching results of expensive function calls to avoid redundant computation (Correct answer)
- Managing memory allocation
- Logging function execution
Correct answer: Caching results of expensive function calls to avoid redundant computation
Memoization stores previously computed results so repeated calls with the same input return instantly.
Question 7: In Git, what does `git stash` do?
- Deletes the current branch
- Commits all staged changes
- Temporarily shelves uncommitted changes so the working directory is clean (Correct answer)
- Merges two branches together
Correct answer: Temporarily shelves uncommitted changes so the working directory is clean
git stash saves dirty working directory changes onto a stack so you can switch contexts cleanly.
Which of the following correctly describes a hash collision?