Larsen & Toubro interview prep
9 practice questions on the topics candidates reported from Larsen & Toubro interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
Practise them as a timed round19 roles open at Larsen & Toubro
DSA 3
-
Which of these runs in O(log n) time on n items?
- Binary search for a key in a sorted array
- Finding the largest value in an unsorted array
- Comparing every pair of elements
- Printing every element
Show the answer
A. Binary search for a key in a sorted array
Binary search halves what is left on every step, so it needs about log2 n steps: 20 steps for a million items. A scan of every element is O(n), and comparing every pair is O(n^2). n is the size of the input.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
-
Which of these is a non-linear data structure?
- Array
- Tree
- Queue
- Linked list
Show the answer
B. Tree
In a linear structure each element has at most one successor, so it can be walked in one sequence: arrays, stacks, queues, linked lists. A tree node can have several children, and a graph several neighbours, so they branch.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
-
When is a linked list a better choice than an array?
- When you need fast access to the i-th element
- When you often insert or delete in the middle at a position you already hold, and do not need indexing
- When memory per element must be as small as possible
- When the data must be sorted by binary search
Show the answer
B. When you often insert or delete in the middle at a position you already hold, and do not need indexing
With a pointer to the node, a list relinks in O(1), while an array shifts everything after the position in O(n). In exchange a list has O(n) indexing, a pointer per node and poor cache locality, which is why arrays and vectors win in most real code.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
Python 1
-
A valid password has at least 8 characters, a digit and an upper-case letter. What does this print?
def valid(p): return (len(p) >= 8 and any(c.isdigit() for c in p) and any(c.isupper() for c in p)) print([valid(p) for p in ["Secret12", "secret123", "Short1A", "LONGPASSWORD"]])- [True, True, False, False]
- [True, False, False, False]
- [True, False, True, False]
- [False, False, False, False]
Show the answer
B. [True, False, False, False]
"Secret12" passes all three. "secret123" has no capital, "Short1A" has only 7 characters, and "LONGPASSWORD" has no digit. any() stops at the first character that matches, and and stops at the first rule that fails.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
C and C++ 2
-
A std::vector is full and push_back is called. What happens, and what is the cost per push_back on average?
- It links a new block without moving anything; O(log n)
- It throws std::length_error
- It allocates exactly one more slot each time; O(1) every time
- It allocates a larger buffer (usually about twice as big) and moves the elements over; amortised O(1)
Show the answer
D. It allocates a larger buffer (usually about twice as big) and moves the elements over; amortised O(1)
When capacity runs out, the vector allocates a bigger block and moves or copies the elements. Growing by a constant factor means the copies average out to a constant per element. Call reserve when you know the size up front.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
-
How do lookups in std::map and std::unordered_map compare?
- map is O(1) and unordered_map is O(log n)
- Both are hash tables, O(1)
- map is a balanced tree, O(log n) and kept in key order; unordered_map is a hash table, O(1) on average
- Both are O(n), because they scan their keys
Show the answer
C. map is a balanced tree, O(log n) and kept in key order; unordered_map is a hash table, O(1) on average
std::map is usually a red-black tree, so lookups are O(log n) and iteration is in sorted order. std::unordered_map hashes the key, O(1) on average and O(n) in the worst case, with no useful order.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
DBMS and SQL 2
-
What does a FULL OUTER JOIN of tables A and B return?
- Only rows that match in both
- Every row from both tables: matched rows joined, and unmatched rows from either side with NULLs for the other side's columns
- Every row from A only
- Every combination of rows from A and B
Show the answer
B. Every row from both tables: matched rows joined, and unmatched rows from either side with NULLs for the other side's columns
INNER keeps matches only, LEFT adds unmatched A rows, RIGHT adds unmatched B rows, FULL adds both. Every combination is a CROSS JOIN. MySQL has no FULL OUTER JOIN and emulates it with a LEFT JOIN UNION a RIGHT JOIN.
This topic is named in a candidate’s interview report: L&T-NxT graduate engineer trainee interview, 2021, on GeeksforGeeks.
-
What makes a DBMS relational (an RDBMS)?
- It stores data in files
- It needs no schema
- It can only hold one table
- It keeps data in tables of rows and columns related through keys, enforces integrity constraints and is queried with SQL
Show the answer
D. It keeps data in tables of rows and columns related through keys, enforces integrity constraints and is queried with SQL
A DBMS is any system that manages a database, including file-based, hierarchical and document stores. An RDBMS such as MySQL, PostgreSQL or Oracle adds the relational model: tables, primary and foreign keys, joins and ACID transactions.
This topic is named in a candidate’s interview report: Graduate engineer trainee on-campus interview, 2022, on GeeksforGeeks.
Machine learning 1
-
How are artificial intelligence, machine learning and deep learning related?
- They are three names for the same thing
- Deep learning is a kind of machine learning (many-layered neural networks), and machine learning is one way of building AI
- Machine learning includes AI
- Deep learning has nothing to do with neural networks
Show the answer
B. Deep learning is a kind of machine learning (many-layered neural networks), and machine learning is one way of building AI
AI is the broad goal of machines doing tasks that need intelligence, including hand-written rules. ML learns the rules from data. Deep learning is the part of ML behind speech recognition in voice assistants and most modern vision and language models.
This topic is named in a candidate’s interview report: Graduate engineer trainee on-campus interview, 2022, on GeeksforGeeks.