This is the third part of the series on online assessments that I witnessed during the season of 2024. The previous parts can be found here and here.
- Phone Pe
- Oracle
- Confluent
- Amazon
- Seimens
- Walmart
- Winzo
- Typeface
- Media.net
- Samsung Research Institute Bangalore (SRIB)
Phone Pe
Other Campus Questions
-
You are given a tree with nodes. Each node has amount of apples on it. You start walking from the node , and on the walk you randomly choose any unvisited node connected to the current node with equal probability. You can only visit each node once. You can eat the apples on the node you are currently on. What is the expected number of apples you will eat?
Solution
We will perform a single DFS to calculate the same. The time complexity of the same would be .
-
There are numbers of a board. In one operation, you will pick two numbers and from the board, erase them and add the following number back to the board:
- if both and have the same parity.
- if both and have different parity.
Calculate how many different final numbers can be present on the board.
Constraints:
-
There is a contest where two flags have been placed among checkpoints on the map of Haven. Checkpoints are connected by roads, it is possible that there are checkpoints between which no path exists, meaning there are no roads connecting them. You are given a checkpoint where you will start your journey, and you have to collect both flags, placed at checkpoints and in order ( first and then ). You can pass through checkpoints more than once. However, you have to pay a price to use the road, so if someone goes along a road then every time he should pay the price for that road. You are given an array of costs of size . You have to distribute prices such that each price of the road corresponds to only one road, so that the cost of collecting both flags will be minimal and hence win the contest. You cannot rearrange prices after the start of the contest. It is guaranteed that there are no self loops or multiple edges in the graph.
Constraints:
Solution
-
Raju works for PhonePe and needs to deliver QR codes to Vanous merchants in a city laid out as an inom grid, Each shop in the grid requires a certain number of QR codes. Raju starts his journey at the top-left corner of the grid and needs to reach the bottom-right corner . He can only move right or down at any step. Raju wants to distribute the maximum number of QR codes in a single commute. But there’s a twist, To assist a merchant more efficiently Raju chooses to double the number of QR codes for one specific merchant along his path. However, he can only do this for one shop in his entire Journey. Your task is to help Raju determine the maximum number of QR’s he would need on his way to the destination, Help considering the option to double the value of exactly one cell.
Constraints:
Solution
-
To ensure seamless transactions, PhonePe needs to optimize its server network to minimize communication costs across these locations You are given a network of machines, which can either be server machines or client machines, and directed, weighted edges representing the network cost to travel from one machine to its neighbor machine. If a path exists from one machine to another, then network cost is defined as the sum of edge weights via that path. Your task is to determine the minimum sum of network cost to reach all machines (client and server machines) from any server. Additionally, each client machine can be upgraded to a server machine at a given one-time cost. This means the number of server machines will increase by , but with additional cost.
- The cost to reach itself for a client machine with server capabilities is zero since reaching itself needs no edge traversal.
- The cost to reach a server machine from itself is zero.
Input Format:
- An integer representing the total number of machines. Machines are labeled from to
- An integer representing the total number of client.
- : A list of integers containing client machine nodes.
- An integer representing the total number of server machines.
- A list of integers containing server machine nodes.
- An integer representing the number of directed, weighted edges.
- A list of tuples , where is the starting machine, is the destination machine, and is the network cost to travel from to .
- An integer representing the number of upgradable client machines
- A size two dimensional integer list , where denotes client machine node and denotes upgradation cost to have server capabilities.
Return the minimum network cost sum. Return if it is not possible to reach all machines. Since the answer can overflow, you need to return the answer modulo .
Constraints:
Solution
We will use a bitmask on the upgradable servers and a multi-source Dijkstra to solve this problem. The time complexity of the solution would be .
-
There are houses numbered from to . Alice is intially at house , and Bob is at house . In one second, they can either move one house to the left or one house to the right. What is the minimum time they need to visit all the houses atleast once? There are testcases in one test file.
Constraints:
Solution
-
There is a country with cities and directed edges between them. It is desired to reorient the edges so that every city is reachable from every other city. Figure out the minimum cost to do the same. A city has atmost edges in this nation. The cost of reversing a directed edge is equal to the weight of the edges. It is gauranteed that a solution always exists for the provided setting.
Constraints:
Solution
Under the given conditions, it can be seen that the final layout with be that of a loop. Thus we just need to figure out the minimum cost to make a loop. The time complexity of the solution would be .
-
There are hurdles in a course and crossing each one increments your score by . An athelete can only cross at max consecutive hurdles on the course. What is the maximum score any athlete can get on the course?
Constraints:
Solution
We will use dynamic programming to solve this problem. Let us denote as the minimum sum of elements I must remove from the array such that the condition mentioned in the question holds. We also define to be equal to , and the value of can be calculated as for the previous indices with respect to . We will use a deque to calculate the range minimum. The time complexity of the solution would be .
-
There are cities in a country. You need to start at city and end at city . Between any two cities, you can either take a plane or a boat. The cost for both of them would be given. You want to plan your journey in such a manner that you change your mode of travel between cities (i.e. from plane to boat, or from boat to plane) at most once in the whole journey. Find the minimum cost of the travel.
Constraints:
Solution
-
You are given an array of length . In each step you do the following:
- Add the sum of the array to your score.
- If the length of the array is , the game ends.
- You partition the array into two parts, such that both the parts are non-emtpty. You repeat the game with each part individually, and then add the score of both the parts to your score.
What is the maximum score you can get?
Constraints:
Solution
We will greedily always parition the rest of the subarray and remove the smallest element from the subarray. The time complexity of the solution would be due to sorting.
-
You are given an array of length . Count the number of subarrays of the same whose has an even number of divisors.
Contraints:
Solution
-
Given a string , find the number of substrings of that have length atleast , length atmost , and have less than or equal to distinct characters present in them.
Constraints:
Solution
We will use a two-pointer approach to solve this problem. We have calculated an utility that calculates the number of substrings with length at most and having atmost distinct characters. Using the same, we can calculate the required quantity in the question. The time complexity of the solution would be .
-
There is an undirected graph of vertices, connected by bidirectional edges. People are standing on each node of the graph connected by a rope inside of this graph. There are ends of the rope: head is at vertex and it’s tail is at vertex . The people connected by this rope occupy all vertices on the unique simple path between and . The people want to know if they can reverse their order, meaning that the person standing at the head of the rope needs to move to the node where the rope’s tail is, and the person standing on the tail node needs to move to the node where the rope’s head is. Unfortunately, the people’s movement is restricted to the graph structure.
In an operation, the person on the head can move to an adjacent vertex not currently occupied. When the person at the head does this each person connected will also move one vertes closer to the head, so that the length of the rope remains unchanged. Similarly, the person standing on the tail vertex can move to an adjacent verter not currently occupied. When the person at tall does this cach person connected will also move one vertex closer to the tail. Determine if it is possible to reverse the people with some sequence of moves.
Constraints:
This is a restatement of the question The Majestic Brown Snake.
-
You are monitoring the building density in a district of houses. The district is represented as a number line, where a house can be built at each numbered point on the line if at least one of the neighboring points is not occupied. Initially, there are no houses in the district. You are given , an array of integers representing the locations of new houses in the order in which they will be built. After each house is built, your task is to find the longest segment of contiguous houses in the district. It is guaranteed that all of the house locations in queries are unique and no house was built at a point with existing houses on both left and right adjacent points.
Constraints:
Solution
Online Assessment Questions
-
Checking if the given graph was bipartite.
-
You are given an array of length . What is the shortest subarray that you must remove from the same so that the sum of the leftover array is divisible by ?
Constraints:
-
What is the number of subsets of the numbers such that if is present in a subset, then and are not present in the same? Return the answer modulo .
Constraints:
-
There is a grid of bricks of size . You make attacks on the same. Each attack is represented as where you destroy the brick in the row and column at the time . Find the minimum time after which there is atleast a square hole of size in the wall.
Constraints:
Oracle
Other Campus Questions
-
You are given two integer and . You need to find an integer such that and the value of is maximum. Here, denotes the bitwise XOR operation. Return the value of modulo .
Constraints:
Solution
We will iterate over all the bits of and and try to set try to set the bit of both the numbers obtained after the XOR to . If the same is not possible, we first prefer set the same in the smaller number. The time complexity of the solution would be .
-
You are given an undirected connected graph witn nodes and edges. You first need to construct any traversal of the graph, and store it in array . All the nodes must be visited atleast once in this traversal. Then you need to construct another array from the array , such that is a subsequence of consiting of only the first occurences of every node. Thus the length of would be exactly . Find the lexographically maximum sequence that can be generated by chosing the array optimally.
Constraints:
Solution
-
Count the number of subsequences of string in the given string . Return the answer modulo .
Constraints:
Solution
-
You are given an integer . Find the smallest number greater or equal to which has no consecutive one’s in it’s binary representation.
Constraints:
Solution
We would iterate from right to left, and maintain a mask to find the occurence of in the digit. As soon we find the same, we increment the prefix by and replace the suffix of the number with bits.
-
Alex is working on a planet where there are days in a year. He noticed that his performence on the day of the year was equal to . Alex is a hard worker and he wants to come to work for the max number of days that he can. However, he does not want to have a negative total perfonttance at any point in time since his boss will deduct his salary. Help Alex find the major number of days in the year that he can come to the office.
Constraints:
Solution
-
You are given an array . In one operations, you are required to choose a range such that it has not been chosen previously, and then add the value of to your score. What is the maximum score you can obtain after performing at max operations?
Constraints:
Solution
-
You are given a string . Find the length of the minimum substring of that must be removed from the same, so that the remaining string can be permuted to form a palindrome. String only consists of lowercase English alphabets.
Constraints:
Solution
-
You are given points on a grid. Calculate the area of the minimum square that encloses at-least of the points in the grid. The points that lie on the boundary of the square are not counted as to be enclosed in the same.
Constraints:
Solution
-
You are given a tree of nodes. You need to colour the nodes of the tree with colours, such that no two adjacent nodes, as well as two nodes that are adjacent to a common city have the same colour. Output the number of colourings of the graph modulo .
Constraints:
Solution
MCQ Related Facts
-
2-3 Trees are a type of balanced search tree data structure that is used to store sorted data and allows for search, sequential access, insertions, and deletions in logarithmic time. A 2-3 tree is a B-tree of order 3.
- They are always balanced and support search, insert, and delete operations in time, which can take upto time in a binary search tree.
- Every non-leaf node in a 2-3 tree has either two children and one data element or three children and two data elements. All the leaves of the tree are at the same level.
- They require more space than binary search trees as the internal nodes do not store the keys and associated data, and are for internal organization only.
-
ARP
orAddress Resolution Protocol
is a protocol used for mapping an IP address to a MAC address that is recognized in the local network. The protocol is used when information is needed to send a packet to a device on the same network. It is a layer protocol. -
/etc/passwd
is a text file that contains information about the users on a Unix-like operating system. It is used to store the essential information required during login. The file contains the user’s username, user ID, group ID, home directory, and shell. -
/etc/hosts
is a text file that maps hostnames to IP addresses. It is used to resolve hostnames to IP addresses when DNS is not available. The file is used by the operating system to map hostnames to IP addresses before querying a DNS server. -
CAP
orConsistency, Availability, and Partition Tolerance
is a theorem that states that it is impossible for a distributed system to simultaneously provide all three guarantees. The theorem is used to describe the trade-offs that must be made when designing distributed systems. -
The latest long term release of Oracle Database is
Oracle Database 23ai
. -
The interrupt defined for system calls in Unix is
128 (0x80)
. The Linux kernel registers an interrupt handler namedia32_syscall
for this interrupt.
Online Assessment Questions
The MCQs were exactly repeated from other campus and previous year questions. Everyone had one different coding question, but the same was of easy to medium difficulty level on LeetCode.
-
You are given a weighted undirected graph of nodes. You need to start from node , end at node , and visit the nodes and in between your journey (in the same order). You are allowed to visit the same nodes multiple times. What is the minimum distance of the total journey?
Constraints:
Confluent
Online Assessment Questions
-
You are given a string of length consisiting of lowercase English letters. You need to count the number of substrings of such that the substring only consists of vowels, and all the vowels are present in the same atleast once.
Constraints:
-
Same question as from the Online Assessment Questions from
Pace Stock Broking
-
A lottery ticket is present by the number , and the value of the lottery ticket is equal to the sum of the digits of . In a lottery sessions, all the ticket numbers between and (both inclusive) have been sold. A ticker is considered a winner if the value of the ticket is equal to the value decided by the organizers. Count the number of values that the organizers can choose so that the number of winners in the draw is maximized. Also return the number of people that would be winning the lottery in the said value is chosen.
Constraints:
Amazon
Online Assessment Questions
-
There are two arrays of length , namely and . In one operation, you can choose two indexes and , and decrement by and increment by . This operation can only be performed if remains non-negative after the operation. You need to find the maximum number of indexes that can be made equal in both the arrays by performing the operations.
Constraints:
Solution
-
You are given an array . In one operation, you can decrease the value of one element by units, and the value of all the other elements by units. If is gauranteed that . What is the minimum number of operations to make the value of all the elements of the array less than or equal to ?
Constraints:
-
You are given base strings. Then you are strings as queries. For each query, you need to determine if there exists atleast one string from the provided strings such that the following conditions hold:
- The length of the query string is equal to the length of the base string.
- The query string differs from the base string in exactly one position.
Constraints:
Solution
We will make use of string hashing to solve this problem.
-
You are given an array representing multiple intervals . You need to count the number of intersections between all the pairs of the intersections.
Solution
-
You are given an array representing multiple intervals . For each interval, determine the number of intervals that the same intersects with. Two intervals are said to intersect if they have atleast one common element.
Solution
Seimens
Other Campus Questions
-
Bob developed a search game where he stores special sequences in a database. The sequences are stored in an array of strings called “games” and each sequence is of size . Afterwards, Bob asks a bot queries. When a query is made, the bot searches the database for any previously stored games. A special sequence is provided in each query. The special sequence is written as where the initial sequence and the terms are all and must be ignored when processing the input. The bot’s task is to find the number of games stored in the database that have the provided sequence as a prefix.
Constraints:
Solution
-
Two players, Player and Player , are playing a game on a board. The board has an origin cell at and extends infinitely in positive coordinates. There are stones placed on the board, each located in a cell . Each player can move a stone from it’s current position to a new cell or (they can’t be placed on negative coordinates). The only requirement is that must be a prime number, and the new cell has to be within the board’s valid range. If a player cannot move any stone, they lose the game.
Both players are strategic in their moves, and Player goes first. Which player wins the game? If it’s Player , print
A
, otherwise, printB
.Constraints:
Solution
-
Alice and Bob have integers represented by arrays and respectively of length each. For some integer value they want to achieve the sum on their respective array to be at most . Both are allowed to do some operations. In a single operation, choose any index element and replace it with . Determine who can achieve the sum at most in a minimum number of operations. Print
Alice
if she can achieve the required sum in less number of operations than Bob, or printBob
if he can achieve the required sum in less number of operations than Alice. PrintTie
in the case of a tie.- If Alice starts doing operations, Bob waits for her to finish, and vice versa.
- Both Alice and Bob start with the original array and array in their respective turn.
- based indexing is followed.
Constraints:
Solution
Online Assessment Questions
There were sections in the test and each section had it’s own time limit of approximately minutes. The sections were as follows:
-
Mental Ability & Aptitude:
- 20 Questions in 20 minutes.
- Typical questions on probability, permutations, combinations, and series that required a good amount of calculations.
-
Digital Logic
- 16 Questions in 25 minutes.
- Topics like Verilog, KMap, Boolean Algebra, Multiplexers, Decoders and Number Representation were covered.
-
Software Engineering
- 16 Questions in 20 minutes.
- A lot of questions were based on C++ and OOPS.
- Most of the questions were based on guessing the output or the error in the code.
-
Coding
- 2 Questions in 20 minutes.
- You are given a graph with nodes and edges. You need to find the number of pairs of nodes in the graph such that the two nodes do not belong to the same connected component.
- You are given an integer array of even length. The rank of the biggest element of the array is , the rank of the second biggest element is , and so on. You need to find the absolute difference between the sum of the ranks of the elements in the first half of the array and the sum of the ranks of the elements in the second half of the array.
Walmart
Other Campus Questions
-
You are given a box of crayons with different colors represented by different alphabets. In one operation, you can remove several continuous crayons of the same color. You may perform this operation several times until the box is empty. Each time you can choose the crayon set, they must be continuous and of the same colors (the set of crayons, ). After removing them, you will get points. You are given an integer where denotes the total number of crayons in the box. You are also given an array colors denoting the colors in the box where each color is represented by an English alphabet. Return the maximum points, you can get in the given scenario.
Constraints:
Solution
The problem can be solved using dynamic programming. Let denotes the maximum score that we can achieve by removing the crayons from to and we have continuous crayons of the same color as the crayon. Refer to the solution to see the transition. Careful handling of states is needed to avoid wrong memoization. The time complexity of the solution is .
-
You are given an array of size . The power of the array represents the sum of the values that you obtain after performing the described operations for times. Your task is to delete the array by performing the following operations in exactly turns.
- For any ; where , delete either of the end (first or last elements of remaining array).
- Before deleting that element (let’s say at index ), it contributes to the sum of the values as to the power of the array. Here , represents the number of turn in which you are performing the operation, and represents the value of the maximum element that is present in the remaining array before the turn is performed.
You are required to perform this in such a way that you maximize the value of the power of the array. Print the maximum value of the power that can be obtained after the array is completely deleted.
Constraints:
Solution
-
Count the sum of XOR values of all the subarrays of the provided array with length . Provide the sum of the XOR values modulo .
Constraints:
Solution
-
You are given an array of length . What is the maximum sum of XOR values of two non-overlapping subarrays of ?
Constraints:
Solution
Online Assessment Questions
-
Shilpa wants to go to a movie with her friends. There are friends including Svipa. different offers are available. A different number of tickets are sold at different group booking rates. For example, a single ticket may cost rupees, two tickets may cost rupees together. The ticket seller always introduces offers which are always equal to the number of friends . Determine how can he do it given and the costs for the tickets together, . Ticket seller would like to maximise his profit.
Constraints:
Solution
-
After delivering a lecture on rainwater harvesting on Environment day, the Director of the Institute asks students to construct a pit that allows rainwater harvesting in the backyard. The recharge pit is made up of cells, where is the number of departments and is the number of students from each department. Each student has to raise or lower the soil level in the cell allotted to him/her to harvest rainwater. The students work as a team and decide the level of each coll considering the slope of the land, porosity, and texture of the soil. After completing the work, the final layout is represented as integers where represents the ground level at the cell . Negative values represents dug up areas and positive values represents raised areas. Water can be trapped in a cell only if all the four sides of a cell are above the cell level. You are given the elevation map which shows the level of each cell. Write a program to find the quantity of water that can be trapped in the recharge pit.
Constraints:
Solution
Winzo
Online Assessment Questions
-
You are given two strings and representing the two deck of cards of length each. Two players are playing the game. The game is started by player . The player in his turn can choose either of the string, and take one card either from the beginning or the end of the string, and add the score associated with the same to his score. The objective of the game is to maximise the score. If both of the players play optimally, what will the difference in the score of player and player finally?
- The score associated with Ace is , King is , Queen is , Jack is , and the rest of the cards have the same score as their face value.
- Ace card is represented by
A
, asT
, King asK
, Queen asQ
, and Jack asJ
.
-
You are given an array of length . For each pair of indexes , you need to add to the score if is positive prime number. Calculate the score for the given array.
Constraints:
-
You are given a matrix of size . You need to go from the first row to the last row. You cannot step into the same column for two consecutive rows. Find the maximum sum that can be obtained.
Constraints:
Typeface
Other Campus Questions
-
You are given an array of length representing the heights of the towers in a line. A tower is visible from the tower if all the towers between and have height strictly less that the height of tower . For each tower determine the number of towers visible from it both towards the left and the right.
Constraints:
Solution
-
Given an array of integers of length , determine the number of triplets such that and the product is even. Return the count modulo .
Constraints:
Solution
-
Given three strings, , , and , find:
- : The longest substring of text matching the end of
- : The longest substring of text matching the beginning of
Sum the lengths of the two strings to get the . The substring of text that begins with the matching prefix and ends with matching suffix, and has the highest , is the correct value to return. If there are other substrings with equal , return the lexicographically lowest substring.
Constraints:
-
There are points on a grid with coordinates as . Whenever a point is marked, all the points within a distance of units in the same column and row of the marked points are also automatically marked. Note that the marking of the points is transitive and chainable. What is the minimum number of points you need to mark to finally mark all the points?
Constraints:
Solution
Online Assessment Questions
-
You are given a directed graph of nodes. You are also given nodes in array . Return the count of the descendants of any of the given nodes.
Constraints:
-
You are given an array of umbrella sizes as of length . You need to get the umbrellas to so that the total size of them is exactly . What is the minimum number of umbrellas that you need to buy? You can buy the same sized umbrella multiple times.
Constraints:
-
You are given a undirected weighted tree of nodes. Each node is associated with a value . You need to determine the number of valid pairs in the graph. A pair is called valid only if is an ancestor of (not equal to ) and the distance between and is less than or equal to .
Constraints:
Media.net
Other Campus Questions
-
You are given a tree of nodes. You need to find the maximum XOR of the subtree sums of two non-overlapping subtrees in the given tree. The tree is assumed to be rooted at node .
Constraints:
Solution
-
Solution
-
Difference between Maximum and Minimum Price Sum
Solution
-
You live in Orange town. There are a lot of markets around that are connected with roads. These markets sell oranges at some prices. The town is not very well developed and they still use carts to transport goods from one place to the other. The roads connect two markets together and have one attribute associated with them. The attribute is the price to go from one market to the other in an empty cart. The town also has a tax factor, the tax factor is the number by which the price associated with a road needs to be multiplied, so it can go from one market to the other IF you are carrying oranges in your cart. So if a road’s original price was coins and tax factor of the town was then in an empty cart it would take coins to travel the road but if the cart contained oranges, it would cost coins.
You wonder what would be the cheapest way to buy oranges if you were initially at each market. You can either buy at the market you’re at or travel to some other market, buy oranges there, and travel back to the original market.
You are given an integer denoting the number of total markets in orange town, an integer array denoting the price of purchasing oranges at each market, a array containing the information about the roads where each row contains three values. The first two values denote the market numbers that are bi-directionally connected via the road and the third value is the price. You are also given an integer , which is the tax factor for the orange town.
Find and return the required array where each element is the minimum cost to buy oranges at each market such that the starting and ending point is that market.
Constraints:
Solution
The key to solving this problem is to realize that we are following a path from to to buy oranges, then you will follow the path in the reverse order from to (and both of the paths will have the shortest cost). This enables us to use the cost of an edge as where is the original cost of the edge and is the tax factor of the town. Now we can use a multi-source Dijkstra algorithm to find the shortest path from all the markets to all the other markets.
-
You are given an array . You need to create an array , which is a subsequence of and satisfies both the following conditions:
- where
- where , is the number of set bits present in the binary representation of and is the bitwise XOR operator.
Let be the bitwise XOR of all the elements in valid array . You need to find the number of different values of that can be formed.
Constraints:
Solution
-
Carl is bored of playing with ordinary prime numbers. Thus, he comes up with some special numbers called Omega Primes. A number is called an omega Prime, if there exists no perfect square such that and such that divides . For example, is an Omega Prime because there is no perfect square except that divides . On the other hand, is not an Omega Prime as (which is a perfect square) is a divisor of .
Carl decides to play a bit more with Omega Primes. He has an array of integers. Carl wants to find the number of different subsets such that the product of elements for each subset, results in an Omega Prime. Help Carl find this number. Since this number can be large, output the answer modulo .
Constraints:
This is a restatement of the question Count Number of Good Subsets on LeetCode.
-
Bitmasks are cool. A bitmask is a string of binary bits ( and ). For example:
01010
is a bitmask. Kuldeep is a naughty but brilliant computer scientist. In his free time, he writes some random programs to play with bitmasks. He has a PhD student under him and to test him (and entertain himself), he has given him the following task:Given a number , write a bitmask of length containing all . Now, you are given operations. Each operation contains two numbers as input. An operation can be one of the following:
- Update operation: Take the XOR of all the bits in the bitmask from index to (both inclusive) with .
- Query operation: Count the number of set bits in the bitmask between index to (both inclusive).
You need to find the sum of all the queries.
Constraints:
-
You are given a graph of nodes and edges and each edge has some time associated with it. There is a policeman standing on each node except Node . All of them get a report that there is thief on Node and the policemen start moving towards it, but all of them have been hungry for days, so they are looking to visit a few restaurants as well, before reaching the node . There are restaurants present on some nodes, and each restaurant has some satisfaction. Now, a policeman will only go to a restaurant if and only if the satisfaction he receives by reaching the restaurant is greater than or equal to the time he has invested in reaching there and then going to the Node . Find and return the number of policemen who will have a meal at a restaurant.
Constraints:
Solution
-
Solution
-
Given a complete rooted tree with nodes numbered to . This tree has it’s leaves at the top and root at the bottom. A complete tree is a tree on every leaf of the tree and in order to get all the fruits you have to shake the tree any number of times. But this tree is a little different than the rest it has following properties:
- Every node has its capacity value that represents the number of fruits a node can hold at any moment.
- Only one fruit falls from each node to its present node in one shake.
- If a number of fruits at a node is more than its capacity then excess fruits (greater than capacity) on that node at that instant will fall to the ground. This process happens instantaneously hence no shake is required.
- The tree is rooted at 1.
- You may assume that root is one level above the ground so all fruits which fall from roots lands on the ground.
You have to find the minimum number of shakes you have to perform such that all the fruits are on the ground.
Constraints:
- for non-leaf nodes
- Initially
Solution
-
You are the prime minister of a country and once you went for a world tour. After years, when you returned to your country you were shocked to see the condition of the roads between the cities. So, you plan to repair them, but you cannot afford to spend a lot of money. The country can be represented as a grid, where is a city The cost of repairing a repairing a road between and is and the cost of repairing a road between and is . Return the minimum cost of repairing roads such that all cities become a connected network. As the cost can be large, return the cost modulo .
Constraints:
Solution
Online Assessment Questions
-
You are given an array of integers. The cost of merging two adjacent integers and is . After the merging, they become a single integer with the value . You need to find the minimum cost to merge all the integers into a single integer.
Constraints:
-
You are given an array . In one operation, you can choose any index , and then update all the indexes in the array as where is the bitwise OR operator. You need to find the minimum number of operations required to make all the elements of the array equal.
Constraints:
-
You are given an array of strings and a target string . In one operation you can choose any string from and take a non empty prefix of the same. Finally at the end, you need to concatenate all the chosen prefixes such that they form the word . You need to find the minimum number of operations required to form the word . You can choose the same string multiple times.
Constraints:
Samsung Research Institute Bangalore (SRIB)
SRIB is known to frequently repeat it’s questions, and the most of them are from the this very helpful repository.
Other Campus Questions
-
You are given segments. Each segment has threw characteristic properties:
- : The starting point of the segment
- : The ending point of the segment
- : The cost of the segment
Two segments can form a valid pair, if and only if those two segments do not overlap. Segments are called overlapping if there is at least one point lying in both the segments. The cost of the pairing of two valid segments is defined as the product of their individual costs. Out of all possible valid pairs, find the valid pair of segments, for which their cost of pairing is minimal. Print that min cost of pairing.
Constraints:
Solution
-
There is a knot in the middle of a necklace with beads at the left and the right. The red and blue beads are randomly strung into it. You want to make the number of red and blue beads equal by removing some of them. As there is a knot in the middle, you cannot remove the beads passing the knot. You can remove them only from each end of the necklace. You are required to print the minimum number of beads you should remove to make the number of the remaining red and blue beads the same. Although removing all the beads from the necklace will always mate the number of both colors equal as zero, there is a way to remove a smaller number of beads. The information of the necklace is given as string whose length is . The colors of the beads are given in order from the left and to the right end. The red bead is expressed as
R
, whereas the blue bead is expressed asB
.Constraints:
Solution
-
Count the number of positive integers less than or less to such that the sum of their digits is . Return the number of numbers modulo .
Constraints:
Solution
-
There are balloons and bullets and each balloon is assigned with a particular number (point). Whenever a particular balloon is shot, the number of points increases by
- The multiplication of points assigned to balloon on left and that of right side.
- Points assigned to left if no right exists.
- Points assigned to right if no left exists.
- Points assigned to itself if no other balloon exists.
You have to output the maximum number of points possible you can get by shooting the balloons.
Constraints:
Solution
-
A doctor travels from a division to other division where divisions are connected like a graph (directed graph) and the edge weights are the probabilities of the doctor going from that division to other connected division. The doctor stays minutes at each division. You will be given a time and you have to find the division which will have the maximum probability of having him.
- If he reaches a point where there are no further nodes then he leaves the lab after mins and goes home.
- The traveling time is not considered, and thus at the end of the min, he will be in next division.
Constraints:
- Number of divisions
- Number of test cases
Solution
-
There are pots. Every pot has some water in it. They may be partially filled, so there is an overflow number associated with every pot which tell how many minimum stone pieces are require for that pot to overflow. So if for a pot value is , it means minimum stone pieces should be put in that pot to make it overflow.
Initially a crow watched those pots and by seeing the water level he anticipated value correctly for every pot (that is he knew to ). But when he came back in evening he found that every pot is painted from outside and he is not able to know which pot has what value. The crow wants some pots to overflow so that he can serve his child appropriately. For overflowing the pots, he needs to search for the stones in forest (assume that every stone has same size).
He wants to use minimum number of stones to overflow the pots. But he doesn’t know now which pot has what value. So the task is to find out the minimum number of stones that the crow requires to make the pots overflow in the worst case.
Constraints:
Solution
-
Solution
Online Assessment Question
-
You are given a grid of of and elements. You need to perform operations on the same. In one operation, you need to choose one column of the grid, and flip the values of all the cells of that column. Calculate the maximum possible number of rows that can have all the elements as after performing operations. There are test cases in one test file.
Constraints:
Solution