Cognizant Technical Screening 3 — Questions and Answers
Question 1: Which HTTP method is idempotent and should be used to update a resource completely?
- POST
- PATCH
- PUT (Correct answer)
- DELETE
Correct answer: PUT
PUT replaces an entire resource and is idempotent — repeated calls produce the same result.
Question 2: What is the worst-case time complexity of QuickSort?
- O(n log n)
- O(n²) (Correct answer)
- O(n)
- O(log n)
Correct answer: O(n²)
QuickSort degrades to O(n²) when the pivot is consistently the smallest or largest element (e.g., already sorted input with naive pivot).
Question 3: In Java, which collection class is synchronized and thread-safe by default?
- ArrayList
- HashMap
- Hashtable (Correct answer)
- LinkedList
Correct answer: Hashtable
Hashtable is synchronized on every method, making it thread-safe, unlike HashMap which is not.
Question 4: What does REST stand for in web services?
- Remote Execution and State Transfer
- Representational State Transfer (Correct answer)
- Resource Encoding and Service Technology
- Relational Entity Service Transfer
Correct answer: Representational State Transfer
REST stands for Representational State Transfer, an architectural style for distributed hypermedia systems.
Question 5: Which of the following is NOT a principle of SOLID design?
- Single Responsibility Principle
- Open/Closed Principle
- Dynamic Inheritance Principle (Correct answer)
- Liskov Substitution Principle
Correct answer: Dynamic Inheritance Principle
SOLID stands for Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion — Dynamic Inheritance is not part of it.
Question 6: In a binary tree, what is the maximum number of nodes at depth d (root at depth 0)?
- d
- 2^d (Correct answer)
- 2d
- d²
Correct answer: 2^d
At depth d, a binary tree can have at most 2^d nodes since each node can have up to 2 children.
Question 7: What does the 'final' keyword mean when applied to a method in Java?
- The method runs only once
- The method cannot be overridden by subclasses (Correct answer)
- The method is static
- The method returns a constant value
Correct answer: The method cannot be overridden by subclasses
A final method cannot be overridden in any subclass, ensuring the method's behavior remains unchanged.
Which HTTP method is idempotent and should be used to update a resource completely?