Paytm
40+ Rupicard Interview Questions and Answers
Q1. 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
Reverse a singly linked list of integers and return the head of the reversed linked list.
Iterate through the linked list and reverse the pointers to point to the previous node instead of the next node.
Use three pointers to keep track of the current, previous, and next nodes while reversing the linked list.
Update the head of the reversed linked list as the last node encountered during the reversal process.
Q2. 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
Q3. 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
Find the minimum time required to rot all fresh oranges in a grid.
Use Breadth First Search (BFS) to simulate the rotting process of oranges.
Track the time taken to rot all fresh oranges and return the result.
If any fresh oranges remain after simulation, return -1 as it is impossible to rot all oranges.
Q4. 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
Q5. 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
Q6. Maximum Subarray Sum Problem Statement
Given an array of integers, determine the maximum possible sum of any contiguous subarray within the array.
Example:
Input:
array = [34, -50, 42, 14, -5, 86]
Output:
137
E...read more
Find the maximum sum of any contiguous subarray within an array of integers.
Iterate through the array and keep track of the maximum sum of subarrays encountered so far.
At each index, decide whether to include the current element in the subarray or start a new subarray.
The maximum subarray sum can be calculated using Kadane's algorithm.
Example: For array [34, -50, 42, 14, -5, 86], the maximum sum is 137.
Example: For array [-5, -1, -8, -9], the maximum sum is -1.
Q7. 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
Implement a function to delete a node at a specified position in a linked list.
Traverse the linked list to find the node at the specified position.
Update the pointers to skip the node to be deleted.
Handle edge cases like deleting the head or tail node.
Return the modified linked list.
Q8. 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
Q9. 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
Q10. 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
Q11. 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
Q12. 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
Q13. 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
Q14. 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
To delete a node in a singly linked list given a reference to the node.
Traverse the linked list to find the node to be deleted.
Update the value of the node to be deleted with the value of the next node.
Point the next pointer of the node to be deleted to the next node's next pointer.
Q15. 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
Q16. 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
Q17. 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
Q18. 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
Sort an array of 0s, 1s, and 2s in increasing order.
Use a three-pointer approach to sort the array in a single pass.
Initialize low, mid, and high pointers at the start, iterate through the array, and swap elements accordingly.
Example: If the current element is 0, swap it with the element at the low pointer and increment both low and mid pointers.
Q19. 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
Print nodes of a binary tree in spiral order traversal.
Use a queue to perform level order traversal.
Alternate between printing nodes from left to right and right to left at each level.
Handle null nodes appropriately.
Example: For input '1 2 3 -1 -1 4 5 -1 -1 -1 -1', output should be '1 3 2 4 5'.
Q20. 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
Create a deep copy of a linked list with random pointers.
Iterate through the original linked list and create a new node for each node in the list.
Store the mapping of original nodes to their corresponding new nodes in a hashmap.
Iterate through the list again to set the next and random pointers of the new nodes based on the mapping.
Return the head of the newly created deep copied linked list.
Q21. 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
Q22. 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
Q23. 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
Delete the middle node of a singly linked list in O(N) time complexity and O(1) space complexity.
Identify the middle node using slow and fast pointers technique.
Update the pointers to skip the middle node.
Handle edge cases like no middle node or two middle nodes.
Perform the deletion in a single traversal of the linked list.
Return the modified linked list after deletion.
Q24. 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
Identify and return the bottom right view of a given binary tree by viewing it from an angle of 45 degrees from the bottom right side.
Traverse the binary tree in a right-to-left manner and keep track of the last node encountered at each level.
Use a queue for level order traversal and update the result array with the last node at each level.
Return the result array sorted in ascending order as the bottom right view of the binary tree.
Q25. 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
Given a list of integers, find the next greater element for each element in the list.
Iterate through the list from right to left and use a stack to keep track of elements.
Pop elements from the stack until a greater element is found or the stack is empty.
Store the next greater element for each element in a result array.
If no greater element is found, store -1 in the result array.
Q26. 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
The task is to find the length of the longest common subsequence between two given strings.
Implement a function to find the longest common subsequence between two strings.
Use dynamic programming to solve this problem efficiently.
Iterate through the strings and build a matrix to store the lengths of common subsequences.
The value in the bottom-right corner of the matrix will be the length of the longest common subsequence.
Q27. 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
Group anagrams together in a list of strings.
Iterate through the list of strings and sort each string to group anagrams together.
Use a hashmap to store the sorted string as key and the original string as value.
Return the values of the hashmap as the grouped anagrams.
Q28. 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
Maximize profit by scheduling jobs within their deadlines.
Sort the jobs array in descending order of profits.
Iterate through the sorted array and schedule jobs based on deadlines.
Keep track of completed jobs and their profits to calculate the total profit.
Return the maximum profit achieved by scheduling jobs within deadlines.
Q29. 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
Q30. 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
The task is to determine the lexicographically smallest array that can be obtained by performing at most 'K' swaps of consecutive elements.
Sort the array in non-decreasing order and keep track of the number of swaps made.
Iterate through the array and swap adjacent elements if it results in a lexicographically smaller array.
Continue swapping until the maximum number of swaps 'K' is reached or the array is lexicographically smallest.
Return the final lexicographically smallest a...read more
Q31. 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
Find the largest element in a sorted array smaller than or equal to a given integer X.
Use binary search to efficiently find the floor value of X in the sorted array.
Compare the middle element of the array with X and adjust the search accordingly.
Return the element before or equal to X as the floor value, or -1 if no such element exists.
Q32. Write a function that returns '3' when '4' is passed as an input and vice versa without using if-else condition
Function to swap '3' and '4' without using if-else
Use XOR operator to swap the values
Convert the input to ASCII code and perform the swap
Use a lookup table to map the values
Q33. A 2D matrix is given which is row wise and column wise sorted. Find a particular element from it
Finding an element in a sorted 2D matrix
Start from the top right corner or bottom left corner
Compare the target element with the current element
Move left or down if the target is smaller, else move right or up
Repeat until the target is found or all elements are checked
Q34. Find the odd repeating element from a set of repeating elements
Find the odd repeating element from an array of strings
Use a hash table to count the frequency of each element
Iterate through the hash table to find the element with an odd count
Q35. design dictionary using trie....having operations of inserting a word, updating and deleting (needed to write full running code)
Design a dictionary using trie with insert, update and delete operations.
Implement a Trie data structure with nodes containing a character and a boolean flag to indicate end of word
For insert operation, traverse the trie and add nodes for each character in the word
For update operation, delete the existing word and insert the updated word
For delete operation, mark the end of word flag as false and delete the node if it has no children
Use recursion for traversal and deletion
Exa...read more
Q37. Given a graph, print all the connected components in it.
Print all the connected components in a given graph.
Traverse the graph using DFS or BFS algorithm.
Maintain a visited array to keep track of visited nodes.
For each unvisited node, perform DFS or BFS and add all visited nodes to a connected component.
Repeat until all nodes are visited.
Print all connected components.
Q38. SQL Query to find Nth highest salary from table
SQL query to find Nth highest salary from table
Use ORDER BY and LIMIT clauses
Use subquery to get the Nth highest salary
Handle cases where there are less than N distinct salaries
Q39. Puzzle on measuring exactly half a glass of water
Fill the glass to the brim, then pour out exactly half.
Fill the glass completely with water
Pour the water into another container until the glass is half full
Pour the remaining water back into the glass
Q40. Write a program to find Minimum length of string in 'bdcabdcbaabbbac' containing substring 'abc'
A program to find the minimum length of a string containing a given substring.
Use a sliding window approach to iterate through the string and check for the substring.
Keep track of the minimum length of the string containing the substring.
Return the minimum length found.
Q41. Write a program to Create a spiral array using 2D-array
Program to create a spiral array using 2D-array
Create a 2D-array with given dimensions
Initialize variables for row, column, and direction
Fill the array in a spiral pattern by changing direction when necessary
Return the spiral array
Sharding is a database partitioning technique to improve performance and scalability by distributing data across multiple servers.
Sharding involves breaking up a database into smaller, more manageable parts called shards.
Each shard contains a subset of the data, allowing for parallel processing and improved performance.
Sharding helps distribute the workload across multiple servers, preventing bottlenecks and improving scalability.
Examples of sharding implementations include M...read more
Q43. Types of DS and a real life scenario.
Types of DS and a real life scenario
Arrays - storing a list of names
Linked Lists - managing a playlist
Stacks - undo/redo functionality in text editors
Queues - managing customer requests in a call center
Trees - organizing files in a computer
Graphs - social network connections
Q44. OOPs in python and explain them
OOPs in Python refers to Object-Oriented Programming concepts like classes, objects, inheritance, encapsulation, and polymorphism.
Classes: Blueprint for creating objects with attributes and methods.
Objects: Instances of classes that contain data and behavior.
Inheritance: Ability to create a new class based on an existing class.
Encapsulation: Restricting access to certain components of an object.
Polymorphism: Ability to use a single interface for different data types.
Q45. what is multithreading
Multithreading is the ability of a CPU to execute multiple threads concurrently.
Allows for parallel execution of tasks
Improves performance by utilizing multiple CPU cores
Requires synchronization to prevent race conditions
Example: Running a web server that can handle multiple client requests simultaneously
Q46. Build Basic LRU without Libraries
Implement a basic LRU cache without using libraries
Create a data structure to store key-value pairs with a fixed size
Use a doubly linked list to keep track of the most recently used items
Implement methods to add, access, and remove items based on their usage
Update the linked list whenever an item is accessed or added
Top HR Questions asked in Rupicard
Interview Process at Rupicard
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month