Houses in Hackerland
The city of Hackerland has many houses, each of which is connected via roads. There are house_nodes number of houses, numbered 0 to house_nodes - 1, where each pair of houses is connected and has a unique shortest path between them. Thus, the network of houses and roads forms an undirected tree structure comprising house_nodes nodes and (house_nodes - 1) edges. Each of the ed
Asked in: Flipkart
Modified Knapsack Problem
The Knapsack problem is a well-known problem in the field of computer programming and problem-solving. To make it more interesting, an interviewer uses a modified version of the problem.
Given n items, where the weight of the i-th item is 2^i, and the cost of the i-th item is cost[i], find the minimum amount needed to purchase the items such that the combined weight o
Asked in: Flipkart
Question 2
Implement a Least Frequently Used (LFU) cache data structure of size cacheSize that handles two types of queries: GET and PUT.
A GET query attempts to retrieve the value of a given key.
If the key is present in the cache, it is returned.
Otherwise, it returns -1.
A PUT query updates or inserts a key-value pair into the cache.
When the cache is full, the least frequentl
Asked in: ShareChat
A forklift operator navigates products within an automotive parts warehouse. The dashboard displays a real-time map showing open and blocked sections as an n x m matrix of 1's (open) and 0's (blocked). The operator starts at the top-left corner of the map at warehouse[0][0] and aims to reach the bottom-right corner at warehouse[n-1][m-1].
Movements can only be made to the right or downward. Giv
Asked in: ShareChat
1. Question 1
Given a chessboard of n rows (top to bottom) and n columns (left to right). In each move, a knight moves either:
2 column positions and 1 row position
2 row positions and 1 column position
In other words, a move is 2 steps along one axis and 1 step along a perpendicular axis.
Given a starting position A and ending position B, calculate the minimum number of moves needed by the k
Asked in: ShareChat
The class uses a novel system where the success of an individual is assigned to a symbol. These symbols have the following precedence:
A > B > C > D > E > F
The symbols are collected and fed into the assessment robot. The success of the class is determined in the following way, with the output in green at the end:
"AAABBCDDEFF"
Sometimes it is ambiguous what the output is. In this case
Asked in: Siemens
4. Question 4
Your colleagues often bring a few books to the office to read, then put them into shared book shelves, so other people have the chance to read it as well. After some days, the shelves have become messier and messier. As the office manager you are tasked to develop a function to sort them.
As the basic information of a book, the name, author and edtion will be recorded.
The fun
Asked in: Siemens
You are a part of the World of Wizardsโa global society of magicians. It's your task to create a "warped-spell" that helps the society ensure the authenticity and secrecy of its members.
All the members meet once a month at a secret club. In order to ensure the authenticity of members, each member is sent a "secret" number of 1-7 digits, 10 days before the meeting.
On the meeting day, each m
Asked in: Siemens
1. Question 1
You've just started as a trainer in Thoughtworks University, and you want to make a good first impression. You start investigating how to make it easier to organise the coding sessions. It turns out that trainers are spending a lot of their time finding out the average confidence of the participants.
The coding sessions are organised based on how confident the participants are
Asked in: Siemens
The Amazon warehouse receives a multitude of packages every day, each assigned a unique identifier from 1 to n. The warehouse manager must sort the packages, not by their identifiers, but rather through a specific process defined by a permutation sorterOrder that ensures optimal processing.
Initially, the number of sorted packages, sortedCount, is zero. In each operation, the manager sifts thro
Asked in: Amazon