Ola Cabs
10+ BYJU'S Exam Prep Interview Questions and Answers
Q1. Problem: Permutations of a String
Given a string STR
consisting of lowercase English letters, your task is to return all permutations of the given string in lexicographically increasing order.
Explanation:
A st...read more
Return all permutations of a given string in lexicographically increasing order.
Use backtracking to generate all permutations of the string.
Sort the permutations to get them in lexicographically increasing order.
Ensure the string contains unique characters to avoid duplicate permutations.
Q2. LRU Cache Design Question
Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:
1. get(key)
- Return the value of the key if it exists in the cache; otherwise, re...read more
Design a Least Recently Used (LRU) cache data structure that supports get and put operations with capacity constraint.
Use a combination of hashmap and doubly linked list to implement the LRU cache.
Keep track of the least recently used item and evict it when the cache reaches its capacity.
Update the position of an item in the cache whenever it is accessed or updated.
Handle both get and put operations efficiently to maintain the LRU property.
Ensure the time complexity of get an...read more
Q3. Count Leaf Nodes in a Binary Tree
Given a binary tree, your task is to count and return the number of leaf nodes present in it.
A binary tree is a data structure where each node has at most two children, referr...read more
Count and return the number of leaf nodes in a binary tree.
Traverse the binary tree and count nodes with both left and right children as NULL.
Use recursion to traverse the tree efficiently.
Leaf nodes have no children, so check for NULL left and right children to identify them.
Q4. Diagonal Traversal of a Binary Tree Problem Statement
Given a binary tree, your task is to determine the diagonal traversal of the tree.
Example:
Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
1 3 6 2 5 4...read more
Diagonal traversal of a binary tree involves traversing nodes diagonally from top to bottom and left to right.
Traverse the tree level by level, starting from the root node.
For each level, keep track of the diagonal nodes and their children.
Use a queue to store nodes at each level and traverse them accordingly.
Example: For input 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the diagonal traversal is 1 3 6 2 5 4 7.
Q5. Minimum Number Of Taps To Water Garden Problem Statement
You are required to determine the minimum number of taps that need to be opened to water an entire one-dimensional garden defined along the x-axis, which...read more
Find the minimum number of taps to water an entire garden along the x-axis.
Iterate over the taps and find the farthest point each tap can reach.
Sort the taps based on their starting points and use a greedy approach to select the taps.
Keep track of the farthest point reachable by the selected taps and the number of taps opened.
Return the minimum number of taps needed to water the entire garden or -1 if it's impossible.
Q6. Number of Islands Problem Statement
You are provided with a 2-dimensional matrix having N
rows and M
columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more
Count the number of islands in a 2D matrix of 1s and 0s.
Use Depth First Search (DFS) or Breadth First Search (BFS) to traverse the matrix and identify connected groups of 1s.
Maintain a visited array to keep track of visited cells to avoid redundant traversal.
Increment the island count each time a new island is encountered.
Consider all eight possible directions for connectivity while traversing the matrix.
Handle edge cases such as out of bounds indices and already visited cell...read more
Q7. Find the Kth Row of Pascal's Triangle Problem Statement
Given a non-negative integer 'K', determine the Kth row of Pascal’s Triangle.
Example:
Input:
K = 2
Output:
1 1
Input:
K = 4
Output:
1 4 6 4 1
Constraints...read more
The task is to find the Kth row of Pascal's Triangle given a non-negative integer K.
Create an array to store the elements of the Kth row of Pascal's Triangle.
Use the formula C(n, k) = C(n-1, k-1) + C(n-1, k) to calculate each element in the row.
Return the array containing the Kth row of Pascal's Triangle.
Q8. Missing Numbers Problem Statement
You are provided with an array called ARR
, consisting of distinct positive integers. Your task is to identify all the numbers that fall within the range of the smallest and lar...read more
Identify missing numbers within the range of smallest and largest elements in an array.
Find the smallest and largest elements in the array.
Generate a list of numbers within this range.
Filter out the numbers present in the array.
Return the missing numbers in sorted order.
Design a toll booth system for Ola cabs with necessary functions and data structures.
Use a queue data structure to manage the order of vehicles waiting at the toll booth.
Implement functions for vehicle entry, toll calculation, and exit.
Store vehicle information such as license plate number, type of vehicle, and toll amount in a hash map.
Utilize a priority queue to handle VIP or premium customers efficiently.
Include a function to generate toll receipts for each transaction.
OLA app system design involves multiple components like user interface, driver matching algorithm, payment processing, etc.
User interface for booking rides and tracking
Driver matching algorithm based on location and availability
Payment processing for seamless transactions
Real-time tracking of rides for both users and drivers
Q11. What is Closure
Closure is a function that captures the environment in which it was created, allowing it to access variables from that environment even after the function has finished executing.
Closure allows a function to access variables from its outer scope even after the function has finished executing.
It is created when a function is defined within another function and the inner function references variables from the outer function.
Closure helps in maintaining state in functional progra...read more
Interview Process at BYJU'S Exam Prep
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month