Find Interview Questions for Top Companies
Ques:- PUZZLE : one circle (radius r) is drawn.You are throwing a stone in it than what is the probability that stone lies near the center?
Right Answer:
The probability that the stone lies near the center of the circle depends on how you define "near." If you specify a smaller circle with radius ( r_1 < r ) around the center, the probability is the area of the smaller circle divided by the area of the larger circle:

[ P = frac{pi r_1^2}{pi r^2} = frac{r_1^2}{r^2} ]

Without a specific definition of "near," the probability cannot be determined.
Ques:- Suppose in an abstract class a function called x(), AND there is another function with the same name in its derived class.Now create pointer for the abstract class, point it to the derived class object
Right Answer:
When you create a pointer for the abstract class and point it to the derived class object, calling the function `x()` will invoke the implementation in the derived class, assuming it overrides the abstract method.
Ques:- What is the difference between window os and ubuntu
Right Answer:
Windows OS is a proprietary operating system developed by Microsoft, while Ubuntu is a free and open-source operating system based on Linux. Windows typically has a more user-friendly interface and is widely used for commercial software, whereas Ubuntu is known for its security, customization, and is often preferred for development and server environments.
Ques:- What is the difference between heap sorting and insertion sorting
Right Answer:
Heap sort is a comparison-based sorting algorithm that uses a binary heap data structure to sort elements, achieving a time complexity of O(n log n). Insertion sort, on the other hand, builds the sorted array one element at a time by repeatedly taking an element from the unsorted portion and inserting it into the correct position in the sorted portion, with a time complexity of O(n^2) in the worst case.
Ques:- Write code for Towers of Hanoi problem
Right Answer:
```python
def towers_of_hanoi(n, source, target, auxiliary):
if n == 1:
print(f"Move disk 1 from {source} to {target}")
return
towers_of_hanoi(n - 1, source, auxiliary, target)
print(f"Move disk {n} from {source} to {target}")
towers_of_hanoi(n - 1, auxiliary, target, source)

# Example usage:
towers_of_hanoi(3, 'A', 'C', 'B')
```
Ques:- Difference between semaphore and mutex
Right Answer:
A semaphore is a signaling mechanism that can allow multiple threads to access a resource, while a mutex (mutual exclusion) is a locking mechanism that allows only one thread to access a resource at a time.
Ques:- There are 25 horses and only 5 horses can be raced at a time and the top 3 are announced in each such race. What is the minimum number of races required to find the top 3 among 25 horses
Right Answer:
The minimum number of races required is 7.
Ques:- Engine is of length 12m. A and B are 2 bogies of 10m length each. Engine can turn only in obtuse angles but not in acute angle. For example Engine can turn as FEH but not as FEA. Now, the task is that I have to exchange the positions of A and B with the help of Engine and the engine should remain at the same place. I tried for 15 minutes but couldnÂ’t solve this problem
Right Answer:
To exchange the positions of A and B using the engine, follow these steps:

1. Move the engine forward to the end of bogie A.
2. Turn the engine to the left (obtuse angle) and push bogie A forward.
3. Move the engine back to its original position.
4. Now, turn the engine to the right (obtuse angle) and push bogie B forward.
5. Finally, move the engine back to the original position to complete the exchange.
Ques:- Provided a string a character and a count, you have to print the string after the specified character has occurred count number of times. Ex: String: “This is demo string” Character: ‘i’ Count: 3 Output: “ng” However, solving this one must take care of corner case when character is not in string or its not in string count number of times etc
Right Answer:
```python
def substring_after_char_count(s, char, count):
occurrences = 0
index = -1

for i in range(len(s)):
if s[i] == char:
occurrences += 1
if occurrences == count:
index = i
break

if occurrences < count or index == -1:
return ""

return s[index + 1:]

# Example usage
string = "This is demo string"
character = 'i'
count = 3
output = substring_after_char_count(string, character, count)
print(output) # Output: "ng"
```
Ques:- Design a website similar to bookmyshow.com for booking cinema tickets but it must be for a single location only which can have multiple theatres in it. In this he wanted me to design a basic rough GUI, relevant database tables and linking GUI to database and also showing the whole data flow in system. Site must also provide features like advance booking, user login, user registration, movie rating option, saving card details etc
Right Answer:
**Basic GUI Design:**

1. **Home Page:**
- Search bar for movies
- List of currently showing movies with posters
- Links to user login and registration

2. **Movie Details Page:**
- Movie title, description, showtimes, and ratings
- "Book Now" button

3. **Booking Page:**
- Select theatre and showtime
- Seat selection (interactive seating chart)
- User login/registration prompt if not logged in
- Payment details form (including saved card option)

4. **User Profile Page:**
- View past bookings
- Rate movies
- Manage saved card details

**Database Tables:**

1. **Users Table:**
- user_id (PK)
- username
- password_hash
- email
- saved_card_details

2. **Movies Table:**
- movie_id (PK)
- title
- description
Ques:- Code: – Given the value of a starting position and an ending position, you have to reach from start to end in a linear way, and you can move either to position immediate right to current position or two step right to the given position. You have the print all the possible path to reach from start to destination. (DP)
Right Answer:
```python
def print_paths(start, end, path=[]):
path.append(start)

if start == end:
print(" -> ".join(map(str, path)))
elif start < end:
print_paths(start + 1, end, path)
print_paths(start + 2, end, path)

path.pop()

# Example usage
start_position = 0
end_position = 4
print_paths(start_position, end_position)
```
Ques:- You are provided a CSV (Comma Separated Values) in file like E1:12, E2:32 etc. You have to generate a tree with maximum height 3 only with the given values in the following manner : E is the root of tree having n nodes to E1, E2, E3 Â… En. E1, have n nodes E11, E12, E13 Â… E1n, this is how things go on second level. Similarly for E111 types of element will be modelled. Restrictions : You can read file only once , you must take care of the fact that if E1 is not in file but say E11 is there you must not include it
Right Answer:
To generate a tree with a maximum height of 3 from the given CSV values, follow these steps:

1. Read the CSV file and parse the values into a list.
2. Create a root node labeled "E".
3. For each entry (e.g., E1:12), create child nodes under "E" for E1, E2, ..., En based on the values present in the file.
4. For each child node (e.g., E1), check for its children (E11, E12, ..., E1n) and add them as children of E1 only if E1 exists in the file.
5. Repeat this for the second level, ensuring that nodes are only added if their parent exists in the file.
6. Stop adding nodes once the height of the tree reaches 3.

This will ensure that the tree is constructed correctly according to the given restrictions.
Ques:- Code :- A simple C program to reverse the words in a string , like if string is “Oracle @ App Dev”, then it should become “Dev App @ Oracle”
Right Answer:
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void reverseWords(char *str) {
int n = strlen(str);
char *result = (char *)malloc(n + 1);
int j = 0;

for (int i = n - 1; i >= 0; i--) {
if (str[i] == ' ') {
result[j++] = ' ';
} else {
int start = i;
while (i >= 0 && str[i] != ' ') i--;
for (int k = i + 1; k <= start; k++) {
result[j++] = str[k];
}
}
}
result[j] = '';
printf("%sn", result);
free(result);
}

int main() {
char str[] = "Oracle @ App Dev";
reverseWords(str);
return 0;
}
```
Ques:- Puzzle: – Two persons X and Y are sitting side by side with a coin in each’s hand. The game is to simultaneously flip the coin till anyone wins. Player X will win if he gets a consecutive HEAD, TAIL however Y will win if he gets a consecutive HEAD, HEAD. Now you have to tell is the game fair or not
Right Answer:
The game is not fair; Player Y has a higher probability of winning.
Ques:- 1 puzzle – In a truck, we can load max. 1000kg, we have 2 types of bags – 15kg, 25kg. The difference between number of bags of each type can be max. 4 . Find an optimum loading
Right Answer:
Load 40 bags of 15 kg and 36 bags of 25 kg.
Ques:- Write a code for inserting two numbers in a text file given n2>n1 and the next entry should not be overlapping like if first was 4,6 next can’t be 5,7.the second n1 has to be greater than first n2
Right Answer:
```python
def insert_numbers(file_path, n1, n2):
with open(file_path, 'a') as file:
# Read existing numbers to check for overlaps
existing_ranges = []
try:
with open(file_path, 'r') as read_file:
for line in read_file:
existing_ranges.append(tuple(map(int, line.strip().split(','))))
except FileNotFoundError:
pass

# Check if the new range overlaps with existing ranges
for (start, end) in existing_ranges:
if not (n2 < start or n1 > end):
print("Overlap detected. Cannot insert.")
return

# If no overlap, write the new range
file.write(f"{n1},{n2}n")

# Example usage
insert_numbers('numbers.txt', 4, 6)
insert_numbers('numbers.txt', 7, 9) # This will work
insert_numbers('numbers
Ques:- Explain multitasking and multiprogramming
Right Answer:
Multitasking refers to the ability of an operating system to execute multiple tasks or processes simultaneously by rapidly switching between them, giving the illusion that they are running at the same time. Multiprogramming, on the other hand, is a method where multiple programs are loaded into memory and the CPU switches between them to maximize resource utilization, allowing for better performance and efficiency.
Ques:- In a bag you have 20 black balls and 16 red balls.When you take out 2 black balls you take another white ball.If you take 2 white balls then you take out 1 black ball and if balls are of different color you take out another black ball.If you continue doing this what is the last ball that will be left
Right Answer:
The last ball that will be left is a red ball.


AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users