Paytm
400+ Leela Electric Interview Questions and Answers
Q1. Puzzle : 100 people are standing in a circle .each one is allowed to shoot a person infront of him and he hands the gun to the next to next person for e.g 1st person kills 2nd and hands gun to 3rd .This continu...
read moreA puzzle where 100 people shoot the person in front of them until only one person remains.
Each person shoots the person in front of them and hands the gun to the next to next person.
This continues until only one person remains.
The last person standing is the one who was not shot by anyone.
Q2. Generate Binary Strings with No Consecutive 1s
Given an integer K
, your task is to produce all binary strings of length 'K' that do not contain consecutive '1's.
Input:
The input begins with an integer 'T', the...read more
Q3. Reverse Linked List Problem Statement
Given a singly linked list of integers, return the head of the reversed linked list.
Example:
Initial linked list: 1 -> 2 -> 3 -> 4 -> NULL
Reversed linked list: 4 -> 3 -> 2...read more
Q4. Longest Consecutive Sequence Problem Statement
You are provided with an unsorted array/list ARR
of N
integers. Your task is to determine the length of the longest consecutive sequence present in the array.
Expl...read more
Q5. SpecialStack Design Problem
Design a stack that efficiently supports the getMin() operation in O(1) time with O(1) extra space. This stack should include the following operations: push(), pop(), top(), isEmpty(...read more
Q6. Minimum Number of Coins Problem
Dora, on her visit to India, decides to enjoy Indian cuisine where payments are accepted only in specific denominations. Your task is to help Dora obtain the minimum number of co...read more
Q7. Subsequence Determination Problem
Your task is to verify if the given string STR1
is a subsequence of the string STR2
. A subsequence means characters from STR2
are retained in their original order but some (or ...read more
Q8. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
Q9. Kth Smallest Element Problem Statement
You are provided with an array of integers ARR
of size N
and an integer K
. Your task is to find and return the K
-th smallest value present in the array. All elements in th...read more
Q10. Search In Rotated Sorted Array Problem Statement
Given a sorted array of distinct integers that has been rotated clockwise by an unknown amount, you need to search for a specified integer in the array. For each...read more
Q11. Sum of Squares of First N Natural Numbers Problem Statement
You are tasked with finding the sum of squares of the first N
natural numbers for given test cases.
Input:
The first line contains an integer 'T', the...read more
The task is to find the sum of squares of the first 'N' natural numbers.
Iterate from 1 to N and calculate the square of each number
Add all the squares together to get the final sum
Return the sum as the result
Q12. Permutations Problem Statement
Given an array of distinct integers, find all possible permutations of the array.
Explanation:
A permutation is a mathematical way of determining the number of possible arrangemen...read more
Q13. String Transformation Problem
Given a string (STR
) of length N
, you are tasked to create a new string through the following method:
Select the smallest character from the first K
characters of STR
, remove it fr...read more
Q14. Geometric Progression Subsequences Problem Statement
Given an array of ‘N’ integers, determine the number of subsequences of length 3 that form a geometric progression with a specified common ratio ‘R’.
Explana...read more
Q15. Middle of a Linked List
You are given the head node of a singly linked list. Your task is to return a pointer pointing to the middle of the linked list.
If there is an odd number of elements, return the middle ...read more
Q16. Minimum Subset Sum Difference Problem
Given an array of non-negative integers, your task is to partition this array into two subsets such that the absolute difference between the sums of the subsets is minimize...read more
Q17. Reverse Alternate K Nodes Problem Statement
You are given a singly linked list of integers along with a positive integer 'K'. The task is to modify the linked list by reversing every alternate 'K' nodes of the ...read more
Q18. Detect and Remove Loop in Linked List
For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.
Expected Complexity:
Aim for a...read more
Q19. Sort an Array in Wave Form
You are given an unsorted array ARR
. Your task is to sort it so that it forms a wave-like array.
Input:
The first line contains an integer 'T', the number of test cases.
For each test ...read more
Q20. Find Nodes at a Specific Distance from Target in a Binary Tree
Given a binary tree, a target node within this tree, and an integer K
, identify and return all nodes that are exactly K
edges away from the target ...read more
Q21. Rotting Oranges Problem Statement
You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:
- 0 - representing an empty cell
- 1 - representing a fresh orange...read more
Q22. Min Stack Problem Statement
Design a special stack that supports the following operations in constant time:
Push(num)
: Insert the given number into the stack.Pop
: Remove and return the top element from the st...read more
Q23. Minimum Falling Path Sum Problem Statement
Given a square array VEC
of integers with N
rows and N
columns, you need to determine the minimum sum of a falling path through this square array. The array has equal ...read more
Q24. Group Anagrams Problem Statement
Given an array or list of strings called inputStr
, your task is to return the strings grouped as anagrams. Each group should contain strings that are anagrams of one another.
An...read more
Q25. Delete a Node from Linked List Problem Statement
Given a linked list of integers, your task is to implement a function that deletes a node at a specified position, 'POS'.
If the specified position is greater th...read more
Q26. Segregate Even and Odd Nodes in a Linked List
You are given the head node of a singly linked list head
. Your task is to modify the linked list so that all the even-valued nodes appear before all the odd-valued ...read more
Q27. Distinct Subsets Count
Given an array arr
of N integers that may include duplicates, determine the number of subsets of this array containing only distinct elements.
The result should be returned modulo 109 + 7...read more
Q28. Reverse a Linked List Problem Statement
You are given a Singly Linked List of integers. Your task is to reverse the Linked List by changing the links between nodes.
Input:
The first line of input contains a sin...read more
Q29. Ninja Technique Problem Statement
Implement a function that determines whether a given numeric string contains any substring whose integer value equals the product of two consecutive integers. The function shou...read more
Q30. Clone Linked List with Random Pointer
Your task is to create a deep copy of a linked list, where each node has two pointers: one that points to the next node in the list, and a 'random' pointer which can point ...read more
Q31. Quick Sort Problem Statement
Sort the given array of integers in ascending order using the quick sort algorithm. Quick sort is a divide-and-conquer algorithm where a pivot point is chosen to partition the array...read more
Q32. Distributing Coins in a Binary Tree
You are provided with the root of a binary tree that consists of 'N' nodes. Each node in this tree contains coins, and the total number of coins across all nodes is equal to ...read more
Q33. Replace 0s Problem Statement
You are given a matrix where every element is either a 1 or a 0. The task is to replace 0 with 1 if it is surrounded by 1s. A 0 (or a set of 0s) is considered to be surrounded by 1s...read more
Number In Arithmetic Progression Problem
Given three integers X
, C
, and Y
, where X
is the first term of an arithmetic sequence with a common difference of C
, determine if Y
is part of this arithmetic sequence.
Q35. Spiral Order Traversal of a Binary Tree Problem Statement
Given a binary tree with 'N' nodes, your task is to print the nodes in spiral order traversal.
Example:
Input:
The binary tree is represented in level o...read more
Q36. Minimum Insertions to Make a String Palindrome
Determine the minimal number of characters needed to insert into a given string STR
to transform it into a palindrome.
Example:
Input:
STR = "abcaa"
Output:
2
Expl...read more
Q37. Zigzag Traversal of Binary Tree
Given a binary tree with integer values in its nodes, your task is to print the zigzag traversal of the tree.
Note:
In zigzag order, level 1 is printed from left to right, level ...read more
Q38. Decode String Problem Statement
Your task is to decode a given encoded string back to its original form.
Explanation:
An encoded string format is
Q39. Problem: Sort an Array of 0s, 1s, and 2s
Given an array/list ARR
consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.
Input:
The input starts with...read more
The task is to sort an array of 0s, 1s, and 2s in increasing order.
Use a three-pointer approach to partition the array into three sections: 0s, 1s, and 2s.
Initialize three pointers: low, mid, and high. low points to the start of the array, mid points to the current element being processed, and high points to the end of the array.
While mid <= high, if ARR[mid] is 0, swap ARR[low] and ARR[mid], increment low and mid. If ARR[mid] is 1, increment mid. If ARR[mid] is 2, swap ARR[m...read more
Q40. Sub Sort Problem Statement
You are given an integer array ARR
. Determine the length of the shortest contiguous subarray which, when sorted in ascending order, results in the entire array being sorted in ascendi...read more
Q41. Longest Common Subsequence Problem Statement
Given two strings STR1
and STR2
, determine the length of their longest common subsequence.
A subsequence is a sequence that can be derived from another sequence by d...read more
Q42. Minimum Fountains Activation Problem
In this problem, you have a one-dimensional garden of length 'N'. Each position from 0 to 'N' has a fountain that can provide water to the garden up to a certain range. Thus...read more
Q43. Maximum Subarray Sum Problem Statement
Given an array ARR
consisting of N
integers, your goal is to determine the maximum possible sum of a non-empty contiguous subarray within this array.
Example of Subarrays:...read more
The task is to find the maximum possible sum of a non-empty subarray of an array.
Iterate through the array and keep track of the maximum sum encountered so far
If the current element is greater than the sum so far, start a new subarray
If the current element plus the sum so far is greater than the maximum sum, update the maximum sum
Return the maximum sum
Q44. Delete a Node in a Linked List
Given a reference to a node in a singly linked list, your task is to delete that node. Every node in the list has a unique value. The head of the linked list will not be provided....read more
Q45. Maze Obstacle Problem Statement
Given an N * M grid representing a maze with obstacles, compute and return the total number of distinct paths from the top-left cell to the bottom-right cell. A cell in the maze ...read more
Q46. Inorder Successor in a Binary Tree
Find the inorder successor of a given node in a binary tree. The inorder successor is the node that appears immediately after the given node during an inorder traversal. If th...read more
Q47. Group Anagrams Together
Given an array/list of strings STR_LIST
, group the anagrams together and return each group as a list of strings. Each group must contain strings that are anagrams of each other.
Example:...read more
Q48. 0-1 Knapsack Problem Statement
A thief is robbing a store and can carry a maximal weight 'W' in his knapsack. There are 'N' items, where the i-th item has a weight 'wi' and value 'vi'. Consider the maximum weig...read more
Q49. Connect Ropes with Minimum Cost
Given 'N' ropes, each having different lengths, your task is to connect these ropes into one single rope. The cost to connect two particular ropes is equal to the sum of their le...read more
The task is to connect N ropes into one rope with minimum cost.
Sort the array of rope lengths in ascending order.
Initialize a variable to keep track of the total cost.
While there are more than one rope, take the two shortest ropes and connect them.
Add the cost of connecting the two ropes to the total cost.
Replace the two shortest ropes with the connected rope.
Repeat the above steps until only one rope remains.
Return the total cost.
Q50. Parth's OCD Challenge
Parth, a budding programmer, has received an array 'ARR' of 'N' positive integers. His OCD is triggered whenever an odd number appears at an even index or an even number at an odd index in...read more
Q51. Delete Middle Node Problem Statement
You are given a singly linked list of integers. The task is to delete the middle node of this list.
Note:
1. If the list has no middle node, return an empty list (NULL). 2. ...read more
Q52. Adding Two Linked Lists
Given two singly linked lists, with each list representing a positive number without leading zeros, your task is to add these two numbers and return the result in the form of a new linke...read more
Q53. Merge Sort Task
Given a sequence of numbers, denoted as ARR
, your task is to return a sorted sequence of ARR
in non-descending order using the Merge Sort algorithm.
Example:
Explanation:
The Merge Sort algorith...read more
Q54. Cube Sum Pairs Problem Statement
Given a positive integer N
, find the number of ways to express N
as a sum of cubes of two integers, A
and B
, such that:
N = A^3 + B^3
Ensure you adhere to the following conditio...read more
Q55. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Q56. All Pairs with Target Sum
Given an array of integers ARR
with length 'N' and an integer 'Target', the task is to find all unique pairs of elements that add up to the 'Target'.
Input:
First line: Integer 'T' - n...read more
Q57. BST Iterator Problem Statement
You are tasked with creating a class named BSTIterator
that acts as an iterator for the inorder traversal of a binary search tree. Implement the following functions:
BSTIterator(...read more
Q58. Smallest Integer Not Representable as Subset Sum
Given a non-decreasing sorted array ARR
of N
positive numbers, determine the smallest positive integer that cannot be expressed as the sum of elements from any p...read more
The task is to find the smallest positive integer value that cannot be represented as a sum of elements of any proper subset of the given array.
The array is sorted in non-decreasing order, so we can iterate through the array and keep track of the maximum sum we can form.
If the current element is greater than the maximum sum + 1, then the maximum sum + 1 is the smallest positive integer that cannot be represented.
If all elements in the array can be represented as a sum of subs...read more
Q59. Closest Leaf in a Binary Tree
Ninja is stuck in a maze represented as a binary tree, and he is at a specific node ‘X’. Help Ninja find the shortest path to the nearest leaf node, which is considered an exit poi...read more
Q60. Job Sequencing Problem Statement
You are provided with a N x 2 2-D array called Jobs
consisting of N
jobs. In this array, Jobs[i][0]
represents the deadline of the i-th job, while Jobs[i][1]
indicates the profi...read more
Q61. LCA in a Binary Search Tree
You are given a binary search tree (BST) containing N nodes. Additionally, you have references to two nodes, P and Q, within this BST.
Your task is to determine the Lowest Common Anc...read more
Q62. Minimum Characters to Make a String Palindrome
Given a string STR
of length N
, determine the minimum number of characters to be added to the front of the string to make it a palindrome.
Input:
The first line co...read more
Q63. How will you implement a shuffle function for a playlist of songs
Implementing a shuffle function for a playlist of songs
Create a new empty playlist
Randomly select a song from the original playlist and add it to the new playlist
Remove the selected song from the original playlist
Repeat until all songs have been added to the new playlist
Return the new shuffled playlist
Q64. Running Median Problem
Given a stream of integers, calculate and print the median after each new integer is added to the stream.
Output only the integer part of the median.
Example:
Input:
N = 5
Stream = [2, 3,...read more
Q65. Minimum Number of Platforms Required
You are provided with two arrays, AT
and DT
, representing the arrival and departure times of all trains arriving at a railway station.
Your task is to determine the minimum ...read more
This question asks to find the minimum number of platforms required at a railway station so that no train needs to wait.
Sort the arrival and departure times arrays in ascending order.
Initialize a variable 'platforms' to 1 and 'maxPlatforms' to 1.
Iterate through the arrival and departure times arrays simultaneously.
If the current arrival time is less than or equal to the current departure time, increment 'platforms'.
If 'platforms' is greater than 'maxPlatforms', update 'maxPla...read more
Diameter of a Binary Tree Problem Statement
Given a binary tree, return the length of its diameter. The diameter of a binary tree is defined as the length of the longest path between any two nodes in the tree.
The diameter of a binary tree is the length of the longest path between any two end nodes in the tree.
The diameter of a binary tree can be calculated by finding the maximum of the following three values: 1) the diameter of the left subtree, 2) the diameter of the right subtree, and 3) the longest path that passes through the root node.
To find the diameter of a binary tree, we can use a recursive approach where we calculate the height of each node and update the diameter at ea...read more
Q67. Ceil Value from BST Problem Statement
Given a Binary Search Tree (BST) and an integer, write a function to return the ceil value of a particular key in the BST.
The ceil of an integer is defined as the smallest...read more
Q68. Bottom Right View of Binary Tree Problem Statement
Your task is to identify and return the bottom right view of a given binary tree.
This involves viewing the binary tree from an angle of 45 degrees from the bo...read more
Q69. Subtree of Another Tree Problem Statement
Given two binary trees, T and S, determine whether S is a subtree of T. The tree S should have the same structure and node values as a subtree of T.
Explanation:
A subt...read more
Q70. Count Ways to Reach the N-th Stair Problem Statement
You are provided with a number of stairs, and initially, you are located at the 0th stair. You need to reach the Nth stair, and you can climb one or two step...read more
The task is to find the number of distinct ways to climb from the 0th step to the Nth step, where each time you can climb either one step or two steps.
Use dynamic programming to solve this problem
Create an array to store the number of ways to reach each step
Initialize the first two elements of the array as 1 and 2
For each subsequent step, the number of ways to reach that step is the sum of the number of ways to reach the previous two steps
Return the number of ways to reach th...read more
Q71. Rotate Matrix by 90 Degrees Problem Statement
Given a square matrix 'MATRIX' of non-negative integers, rotate the matrix by 90 degrees in an anti-clockwise direction using only constant extra space.
Input:
The ...read more
Q72. Minimize Cash Flow Problem
You are provided with a list of 'transactions' involving 'n' friends who owe each other money. Each entry in the list contains information about a receiver, sender, and the transactio...read more
Q73. Container with Most Water Problem Statement
Given a sequence of 'N' space-separated non-negative integers A[1], A[2], ..., A[i], ..., A[n], where each number in the sequence represents the height of a line draw...read more
Q74. Floor Value of X Problem Statement
Given a sorted array A
and an integer X
, your task is to find and return the floor value of X
in the array.
The floor value of X
is the largest element in array A
which is sma...read more
Q75. Buy and Sell Stock Problem Statement
Imagine you are Harshad Mehta's friend, and you have been given the stock prices of a particular company for the next 'N' days. You can perform up to two buy-and-sell transa...read more
Q76. Integer to Roman Conversion
Given an integer N
, convert it to its corresponding Roman numeral representation. Roman numerals comprise seven symbols: I, V, X, L, C, D, and M.
Example:
Input:
N = 2
Output:
II
Exp...read more
Q77. Factorial Calculation Problem Statement
Develop a program to compute the factorial of a given integer 'n'.
The factorial of a non-negative integer 'n', denoted as n!
, is the product of all positive integers les...read more
Q78. Next Greater Element Problem Statement
Given a list of integers of size N
, your task is to determine the Next Greater Element (NGE) for every element. The Next Greater Element for an element X
is the first elem...read more
Q79. Cousin Nodes in a Binary Tree
Determine if two nodes in a binary tree are cousins. Nodes are considered cousins if they are at the same level and have different parents.
Explanation:
In a binary tree, each node...read more
Q80. Trapping Rain Water Problem Statement
You are given a long type array/list ARR
of size N
, representing an elevation map. The value ARR[i]
denotes the elevation of the ith
bar. Your task is to determine the tota...read more
Q81. Kth Smallest and Largest Element Problem Statement
You are provided with an array 'Arr' containing 'N' distinct integers and a positive integer 'K'. Your task is to find the Kth smallest and Kth largest element...read more
Q82. Problem Statement: Parity Move
You have an array of integers, and your task is to modify the array by moving all even numbers to the beginning while placing all odd numbers at the end. The order within even and...read more
Q83. Anagram Pairs Verification Problem
Your task is to determine if two given strings are anagrams of each other. Two strings are considered anagrams if you can rearrange the letters of one string to form the other...read more
Q84. Circular Move Problem Statement
You have a robot currently positioned at the origin (0, 0) on a two-dimensional grid, facing the north direction. You are given a sequence of moves in the form of a string of len...read more
Q85. Binary Tree Diameter Problem Statement
Given a binary tree, determine the length of its diameter. The diameter is defined as the longest path between any two end nodes in the tree. The path's length is represen...read more
Q86. Colorful Knapsack Problem
You are given a set of 'N' stones, each with a specific weight and color. The goal is to fill a knapsack with exactly 'M' stones, choosing one stone of each color, so that the total we...read more
Q87. Odd Even Levels in Binary Tree
Given a binary tree, the task is to compute the modulus of the difference between the sum of nodes at odd levels and the sum of nodes at even levels.
Input:
The first line contain...read more
Q88. Lexicographically Smallest Array Problem Statement
You are given an array ARR
of 'N' integers and a positive integer 'K'.
Your task is to determine the lexicographically smallest array that can be obtained by p...read more
Q89. Prerequisite Task Completion Verification
Given a positive integer 'N', representing the number of tasks, and a list of dependency pairs, determine if it is possible to complete all tasks considering these prer...read more
Q90. How many BSTs are possible with two nodes and three nodes?
Number of possible BSTs with 2 and 3 nodes.
For 2 nodes, only 2 BSTs are possible.
For 3 nodes, 5 BSTs are possible.
Number of BSTs can be calculated using Catalan numbers formula.
Catalan(2) = 2, Catalan(3) = 5.
Q91. Search in a Row-wise and Column-wise Sorted Matrix Problem Statement
You are given an N * N matrix of integers where each row and each column is sorted in increasing order. Your task is to find the position of ...read more
Q92. Find the Longest Palindromic Substring
Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.
If there are multiple longest palindromic ...read more
Q93. Print Nodes at Distance K from a Given Node
Given an arbitrary binary tree, a node of the tree, and an integer 'K', find all nodes that are at a distance K from the specified node, and return a list of these no...read more
Q94. a unsorted array was given and a number x.find out the two elements whose sum is equal to x
Find two elements in an unsorted array whose sum is equal to a given number x.
Use a hash table to store the difference between x and each element in the array.
Iterate through the array and check if the current element is in the hash table.
Return the pair of elements that add up to x.
Q95. Find Subarray with Given Sum
Given an array ARR
of N
integers and an integer S
, determine if there exists a subarray (of positive length) within the given array such that the sum of its elements equals S
. If su...read more
Q96. Diagonal Traversal of a Binary Tree
Given a binary tree of integers, find its diagonal traversal. Refer to the example for clarification on diagonal traversal.
Example:
Explanation:
Consider lines at an angle o...read more
Q97. What is my favourite app and any improvements in it which i want to implement?
My favourite app is Spotify. I would like to see improvements in the algorithm for personalized playlists.
Improved algorithm for personalized playlists
Better integration with social media platforms
Option to create collaborative playlists with friends
Q98. Rahul And Minimum Subarray Challenge
Rahul is learning about arrays and lists. His teacher gave him a task to find the length of the smallest subarray in a given array 'ARR' of size 'N' with its sum greater tha...read more
Q99. 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
Q100. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Top HR Questions asked in Leela Electric
Interview Process at Leela Electric
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month