A coding problem requires finding the longest common substring of two strings. What is the optimal approach?
ABrute force checking all substrings - O(n³) time
BDynamic Programming approach - O(n²) time and space
CUsing two pointers - O(n) time
DRecursive approach without memoization
Correct Answer:
B. Dynamic Programming approach - O(n²) time and space
Explanation:
Dynamic Programming is the standard approach for longest common substring problems, building a table of subproblem results with O(n²) time and space complexity.
TCS employees working on REST APIs should follow which HTTP method for retrieving data without side effects?
APOST
BGET
CPUT
DDELETE
Correct Answer:
B. GET
Explanation:
GET is the HTTP method for safe, idempotent data retrieval without modifying server state. POST creates resources, PUT updates, and DELETE removes resources.
A TCS developer encounters a null pointer exception in Java. What is the PRIMARY cause?
AAccessing or invoking methods on an object reference that points to null
BUsing too many if-else statements
CDeclaring variables without initialization
DUsing loops excessively
Correct Answer:
A. Accessing or invoking methods on an object reference that points to null
Explanation:
NullPointerException occurs when trying to call methods or access properties on a null object reference, which has no actual instance allocated in memory.
In TCS technical assessments, a question asks about polymorphism. Which is NOT a type of polymorphism in OOP?
ACompile-time (Method Overloading)
BRuntime (Method Overriding)
CStatic Polymorphism
DSequential Polymorphism
Correct Answer:
D. Sequential Polymorphism
Explanation:
The two main types of polymorphism are compile-time (static overloading) and runtime (dynamic overriding). Sequential polymorphism is not a recognized OOP concept.