Hot Topics
Persistent Solution
Technical Round
- Question 1
Give an example of real world scenario where you see inheritance.
- Answer
Suppose a child inherits some characteristics from their parents.
- Question 2
There is a base class and derived class both having same function name with same signature, will it compile?
- Answer
Yes, that will compile; And there runtime polymorphism will take place.
Here’s an example in Java:
class Base {
public void print() {
System.out.println(“This is from Base class”);
}
}
class Derived extends Base {
@Override
public void print() {
System.out.println(“This is from Derived class”);
}
}
In this example, the Base
class has a function named print
, and the Derived
class overrides that function with its own implementation. The Derived
class uses the @Override
annotation to indicate that it is intentionally overriding the print
function from the base class. This code will compile without any issues.
Note that when a derived class overrides a function in the base class, it must provide an implementation that is compatible with the function signature in the base class. This means that the number, type, and order of parameters must match exactly. Additionally, the return type of the overridden function must be either the same as or a subclass of the return type in the base class.
- Question 3
How do we get the value of private member of a class without even using a member of that class, nor can you use any friend clause?
- Answer
To get the value of private number of a class we can use virtual function which is a member function declared within the base class.
- Question 4
If two dads and two sons goes down to market and buy apple each, then why they end up buying only 3 apples?
- Answer
The scenario you describe is a classic example of a logical paradox known as the “Two Sons and Two Fathers Paradox”. The paradox arises because the statement “two dads and two sons go down to the market and buy apples, each” can be interpreted in two different ways, leading to two different answers.
If we interpret the statement as meaning that each person buys one apple, then a total of 4 apples would be bought.
However, if we interpret the statement as meaning that each group of two people (i.e. a father and a son) buys one apple each, then a total of only 3 apples would be bought. In this case, each group of two people can be seen as a single entity, rather than as two separate individuals.
The paradox demonstrates the importance of being clear and precise when stating and interpreting information, as even a small ambiguity in language can lead to confusion and conflicting answers.
- Question 5
Reverse linked list using recursion.
- Answer
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int d){
this->data=d;
this->next=NULL;
}
};
void insertAtTail(Node* &head, int val) {
Node* n = new Node(val);
if(head==NULL) {
head=n;
return;
}
Node* temp = head;
while(temp->next!=NULL) {
temp=temp->next;
}
temp->next = n;
}
void print(Node* &head) {
Node* temp = head;
while(temp != NULL ) {
cout < data < next;
}
cout <next);
cout<data<<" ";
}
int main() {
Node* node = new Node(10);
Node* head = node;
insertAtTail(head,20);
insertAtTail(head,30);
insertAtTail(head,40);
print(head);
reverse(head);
return 0;
}
/*
output:
10 20 30 40
40 30 20 10
*/
- Question 6
Find if a number is power of 2.
- Answer
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cout<<"Enter the value"<<endl;
cin>>n;
if(n==0){
cout<<"The number is not power of 2."<<endl;
return false;
}
while(n!=1){
if(n%2 != 0){
cout<<"The number is not power of 2."<<endl;
return false;
}
n=n/2;
}
cout<<"The number is power of 2."<<endl;
return 0;
}
/*
output:
Enter the value
9
The number is not power of 2.
*/
- Question 7
Tell me about your project.
- Answer
Describe your project. He might ask you follow up questions from your project.
- Question 8
What kind of data structure does fb use for keeping track of followers?
- Answer
Graph data structure is used in fb for keeping track of followers.
- Question 9
What is polymorphism and its types?
- Answer
Polymorphism is briefly described as “one interface, many implementation”. Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are two types of polymorphism:
Compile time polymorphism
Run time polymorphism
- Question 10
What happens when you type Google.com?
- Answer
When you type Google.com in the browser:
Browser searches for IP address of that domain
Browser initiates TCP connection with the server
Server processes request and sends back a response
Browser renders the content
- Question 11
What are the four paradigms of OOP?
- Answer
The 4 paradigms of OOP are:
Inheritance: It is a concept of Object Oriented Programming in which a new class is created from the existing one.
Polymorphism: Poly means many and morph means form. A concept that enables programmers to assign a different meaning or usage to a variable, function or an object in different context.
Polymorphism can be of two types:
Runtime Polymorphism
Compile Time Polymorphism
Abstraction: Creating a new data type using encapsulated items that is well suited for an application.
Encapsulation: It is called data hiding and encapsulation is the way of packing data and function into a single unit to hide the implementation details of a class from outer world.
- Question 12
What is RDBMS and difference between RDBMS and DBMS?
- Answer
RDBMS stands for Relational Database Management System which is a program used to maintain a relational database.
RDBMS | DBMS |
1. In RDBMS data are stored in such a way so that they are related to each other. | In DBMS relationship between data is not present. |
2. Normalization is present to remove or reduce redundancy of data and anomalies. | Normalization is not present. |
3. Multiple users can view the dataset at the same time. | Single user can view the dataset at a time. |
4. It stores a large quantity of data. | It stores a small quantity of data. |
5. Data is stored in a tabular form. | Data is stored in a file format. |
6. The time taken to fetch data is fast because of the relational model. | Time taken to fetch data is slower. |
- Question 13
What all processes take place when one searches a query in a search engine?
- Answer
When a user enters a query into a search engine, the following processes take place:
Crawling: Search engines use automated programs called “spiders” or “bots” to scan and index the web pages on the internet.
Indexing: The search engine stores the indexed information in a database and assigns each page a unique identifier called an “index.”
Query processing: The user’s query is processed and compared against the search engine’s index to identify relevant pages.
Ranking: The search engine uses complex algorithms to determine the relevance and importance of the indexed pages and ranks them accordingly.
Result retrieval: The search engine displays the most relevant and authoritative pages for the user’s query, based on the ranking from the previous step.
Result presentation: The search engine presents the results to the user in the form of a list of URLs and short descriptions, known as “snippets.”
- Question 14
Explain insertion and deletion in doubly linked list.
- Answer
In a doubly linked list, each node has a reference to the previous node and the next node in the list. This allows for easy traversal in both forward and backward directions.
Insertion:
To insert a node at the beginning of the list, we create a new node and set its “next” reference to the current head of the list and its “previous” reference to null. Then, we set the previous reference of the current head to the new node and make the new node the new head of the list.
To insert a node at the end of the list, we create a new node and set its “next” reference to null and its “previous” reference to the current tail of the list. Then, we set the next reference of the current tail to the new node and make the new node the new tail of the list.
To insert a node at a specific position, we traverse the list to find the node before the desired position and set its “next” reference to the new node. Then, we set the “previous” reference of the new node to the node before the desired position and the “next” reference of the new node to the node after the desired position. We also update the “previous” reference of the node after the desired position to the new node.
Deletion:
To delete a node from the beginning of the list, we set the “previous” reference of the current head to null and the “next” reference of the new head to the current head’s next node.
To delete a node from the end of the list, we set the “next” reference of the current tail to null and the “previous” reference of the new tail to the current tail’s previous node.
To delete a node from a specific position, we traverse the list to find the node and set the “next” reference of the previous node to the next node of the node to be deleted. We also update the “previous” reference of the next node to the previous node of the node to be deleted.
- Question 15
What is deadlock and how to avoid it?
- Answer
If two or more processes is waiting for having some event but that event doesn’t happen that is called the deadlock.
Deadlock can be prevented using following conditions:
Mutual exclusion
No preemption
Hold & wait
Circular wait
- Question 16
Write a program to find the largest element in an array.
- Answer
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
cout<<"Largest Element: "<<arr[n-1]<<endl;
return 0;
}
/*
outuput:
5
1 7 8 2 14
Largest Element: 14
/
- Question 17
SQL query to get the player name with number of century and highest score (Table: id, player name, Score).
- Answer
Here is an SQL query to get the player name, number of centuries scored, and highest score:
SELECT
player_name,
COUNT(CASE WHEN score >= 100 THEN 1 END) AS number_of_centuries,
MAX(score) AS highest_score
FROM
scores_table
GROUP BY
player_name;
This query uses the GROUP BY
clause to group the records by player_name
. The COUNT
function is used to count the number of times the score is greater than or equal to 100 (a century), and the MAX
function is used to find the highest score for each player. The CASE
statement is used to conditionally count the number of centuries.
- Question 18
Which programming languages do you use regularly in your work?
- Answer
Tell about the language in which you are comfortable.
- Question 19
Do you have any technical certification that make you qualified for this job?
- Answer
If you have then tell about that.