In thread-safe programming at Infosys, which Java construct provides the most granular level of locking?
ASynchronized method
BSynchronized block
CReentrantReadWriteLock
DVolatile keyword
Correct Answer:
C. ReentrantReadWriteLock
EXPLANATION
ReentrantReadWriteLock provides separate read and write locks, allowing multiple readers but only one writer, offering finer-grained control than basic synchronized constructs.
An Infosys project uses Apache Kafka for real-time data streaming. If a consumer group has 5 consumers and the topic has 8 partitions, how many consumers will remain idle?
A3 consumers
B2 consumers
C1 consumer
D0 consumers
Correct Answer:
A. 3 consumers
EXPLANATION
In Kafka, the maximum number of active consumers in a group equals the number of partitions. With 8 partitions and 5 consumers, only 3 will remain idle.
In a HashMap implementation used at Infosys, what happens when the load factor exceeds the threshold?
AThe HashMap is locked and becomes read-only
BThe HashMap is rehashed with a larger capacity
CAll entries are deleted automatically
DThe oldest entries are removed
Correct Answer:
B. The HashMap is rehashed with a larger capacity
EXPLANATION
When the load factor (ratio of entries to capacity) exceeds the threshold, the HashMap is rehashed with approximately double the capacity to maintain performance.
A complex algorithmic problem in Infosys placement requires analyzing a graph with weighted edges. What would be the optimal approach for finding the shortest path?
ADepth-first search (DFS)
BBreadth-first search (BFS)
CDijkstra's algorithm for weighted graphs
DLinear search
Correct Answer:
C. Dijkstra's algorithm for weighted graphs
EXPLANATION
Dijkstra's algorithm is the optimal choice for finding shortest paths in weighted graphs with non-negative weights, with O(E log V) complexity.
A candidate is solving a problem on dynamic programming for the Infosys coding round. The problem involves overlapping subproblems and optimal substructure. What is the minimum number of steps to solve such problems?
A1 step - direct solution
B2 steps - define subproblems and find recurrence
C3 steps - define subproblems, find recurrence, implement with memoization/tabulation
D4 steps - analyze, define, find recurrence, and optimize further
Correct Answer:
C. 3 steps - define subproblems, find recurrence, implement with memoization/tabulation
EXPLANATION
Dynamic programming requires defining subproblems, establishing recurrence relations, and implementing solutions using memoization or tabulation for optimization.