Join Regular Classroom : Visit ClassroomTech

Celebal Tech Interview Questions + Coding Solutions – codewindow.in

Hot Topics

Celebal Tech Solutions

Technical Round

What is Machine learning?

Machine learning is a branch of computer science which deals with system programming in order to automatically learn and improve with experience. For example, robots are programmed so that they can perform the task based on data they gather from sensors. It automatically learns programs from data.

Difference between DL and ML.

Deep learning is basically a part of machine learning which makes use of Neural Networks to copy the human brain behaviour.
Machine learning is a branch of computer science which deals with system programming in order to automatically learn and improve with experience.

Explain React hooks with example.

React Hooks are a way to manage state and side-effects in React functional components. They were introduced in React 16.8 as an alternative to class components and allow developers to use state and other React features without having to write a class.
Here’s a simple example of how you can use the useState hook to manage state in a functional component:
import React, { useState } from 'react';

function Example() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
In this example, we are using the useState hook to create a piece of state called count with an initial value of 0. The useState hook returns an array with two elements: count and setCount. count is the current value of the state and setCount is a function that allows us to update the value of the state.
In the component, we display the current value of count and have a button that, when clicked, updates the value of count using setCount.

What is difference between Pip and Pep8?

Pip and PEP 8 are two different things in the Python programming language:
  1. Pip (short for Pip Installs Packages) is a package management system used to install and manage packages (libraries, modules, etc.) in Python. With pip, you can easily install and manage third-party packages that can be used in your Python projects.
  2. PEP 8 (short for Python Enhancement Proposal 8) is a set of coding guidelines for writing readable and maintainable Python code. It covers aspects such as naming conventions, code layout, and style, and is widely accepted as the de-facto standard for Python code style.
In summary, Pip is a tool for managing Python packages, while PEP 8 is a style guide for writing Python code.

Write the query to display second highest salary from employee table.

Oracle:
SELECT name, MAX(salary) AS salary FROM employee WHERE salary <> (SELECT MAX(salary) FROM employee);
                                                           OR
Common Table Expression: 
WITH T AS ( SELECT * DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk FROM Employees) SELECT Name FROM T WHERE Rnk=2;

Which algorithm is used to train ANN and how does it train it?

There are various algorithms that can be used to train an Artificial Neural Network (ANN), including:
  1. Gradient Descent: Gradient Descent is one of the most commonly used algorithms to train ANNs. It involves computing the gradient (the slope) of the loss function with respect to the network parameters, and then updating the parameters in the opposite direction of the gradient so as to minimize the loss. There are several variants of Gradient Descent, including batch gradient descent, stochastic gradient descent (SGD), and mini-batch gradient descent.
  2. Backpropagation: Backpropagation is an algorithm that is used to train feedforward neural networks, which are the most commonly used type of ANNs. It involves computing the gradients of the loss with respect to the network parameters and updating the parameters based on the gradients. Backpropagation uses an efficient computation graph representation of the network to compute the gradients, and it can be implemented using gradient descent or other optimization algorithms.
  3. Convolutional Neural Networks (CNNs): Convolutional Neural Networks (CNNs) are a type of ANN that is used for image classification and computer vision tasks. They are trained using variants of gradient descent, such as SGD or mini-batch gradient descent.
  4. Recurrent Neural Networks (RNNs): Recurrent Neural Networks (RNNs) are a type of ANN that is used for sequential data, such as time-series data or natural language processing tasks. They are trained using variants of gradient descent, such as SGD or mini-batch gradient descent.
In summary, the choice of algorithm to train an ANN depends on the type of network and the task it is being used for. The most commonly used algorithms are Gradient Descent and Backpropagation, but other algorithms such as Adam and Adagrad may also be used.

Can primary key have null value?

No primary key cannot have NULL value.

Hands-on programming questions on Python decorators, Mapping through list and function.

Here are some hands-on programming questions on Python decorators, mapping through lists and functions:
  1. Decorators: a. Write a Python decorator that logs the execution time of a function. b. Write a Python decorator that ensures that a function is only called if the arguments passed to it are valid, i.e., they satisfy certain constraints.
import time
from functools import wraps

def log_execution_time(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"Execution time of {func.__name__}: {end_time - start_time:.4f} seconds")
        return result
    return wrapper

@log_execution_time
def some_function():
    # some code here
    pass
def validate_arguments(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        # validate the arguments here
        if all(map(lambda x: isinstance(x, int), args)):
            result = func(*args, **kwargs)
            return result
        else:
            raise ValueError("Invalid arguments")
    return wrapper

@validate_arguments
def some_function(*args):
    # some code here
    pass
  1. Mapping through a list: a. Write a Python function that returns a new list with the squares of all the elements in a given list. b. Write a Python function that returns a new list with the cubes of all the elements in a given list.
def square_elements(lst):
    return list(map(lambda x: x**2, lst))

def cube_elements(lst):
    return list(map(lambda x: x**3, lst))
  1. Function: a. Write a Python function that returns the sum of two numbers. b. Write a Python function that returns the product of two numbers.
def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

What are Higher-order functions and Swagger in Python?

  1. Higher-Order Functions: A higher-order function is a function that takes another function as an argument or returns a function as its result. In Python, functions are first-class objects, which means they can be passed as arguments to other functions, returned as values from other functions, and assigned to variables. This allows us to use higher-order functions to write more abstract and reusable code.
For example, consider a function that takes a list of numbers and returns a new list with only the even numbers:
def even_numbers(lst):
    return [x for x in lst if x % 2 == 0]
This function can be written as a higher-order function that takes a list and a function that returns a Boolean value, indicating whether an element should be included in the result:
def filter_numbers(lst, func):
    return [x for x in lst if func(x)]

def is_even(x):
    return x % 2 == 0

even_numbers = filter_numbers([1, 2, 3, 4, 5], is_even)
  1. Swagger: Swagger is a framework for defining, building, and documenting RESTful APIs. It provides a simple way to describe the structure of an API and its endpoints, as well as the request and response formats. Swagger can be used to generate documentation, client libraries, and server stubs in various programming languages, including Python.
In Python, the Swagger API can be defined using the Swagger specification, which is a JSON or YAML document that specifies the structure of the API and its endpoints. This document can then be used to generate client libraries and server stubs, or to serve as the source of truth for the API documentation.
For example, consider the following Swagger definition for an API that returns information about a list of books:
swagger: "2.0"
info:
  title: Books API
  version: "1.0.0"
host: api.example.com
basePath: /books
schemes:
  - http
paths:
  /:
    get:
      description: Returns a list of books
      responses:
        200:
          description: A list of books
          schema:
            type: array
            items:
              $ref: "#/definitions/Book"
definitions:
  Book:
    type: object
    properties:
      id:
        type: integer
        format: int64
      title:
        type: string
      author:
        type: string

 Write a program to check if an input is palindrome or not.

#include <stdio.h>

int main() {
    int n,m,sum=0,temp;
    printf("Enter the number you want to check\n");
    scanf("%d",&n);
    
    temp=n;
    while(n>0){
        m=n%10;
        sum=(sum*10)+m;
        n=n/10;
    }
    
    if(temp==sum){
        printf("It's a palindrome number");
    }
    else{
        printf("It's not a palindrome number");
    }

    return 0;
}
/*
output:
Enter the number you want to check 121
It's a palindrome number
*/

 How is a subquery in DBMS?

A subquery is a query within another query. In a database management system (DBMS), a subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.
A subquery can be used in various parts of a SQL statement, such as the SELECT, FROM, WHERE, HAVING, and IN clauses. It can be used to retrieve data from one or more tables and then used in the main query as a condition to filter the results.
The basic syntax of a subquery in SQL is as follows:
SELECT column_name(s)
FROM table_name
WHERE column_name operator (SELECT column_name FROM table_name WHERE condition);
For example, consider a table named orders with columns order_id, customer_id, and order_total. To retrieve the customer ID of all customers who have placed an order with a total greater than the average order total, we can use the following subquery:
SELECT customer_id
FROM orders
WHERE order_total > (SELECT AVG(order_total) FROM orders);
The subquery in this example calculates the average order total and returns it as a single value. The main query then uses this value as a condition to filter the results and return only the customer IDs of customers who have placed an order with a total greater than the average.

 What is inheritance and what are the types? Is multiple inheritances available in Java?

Inheritance is a mechanism in which an object acquires properties from its parent object. Types of inheritance:
  • Single-level inheritance
  • Multi-level inheritance
  • Hierarchical inheritance
  • Multiple inheritance
  • Hybrid inheritance
In Java multiple inheritance through classes is not possible but it can be achieved using interfaces.

 Why do we use stack data structure for DFS?

Stack data structure is used for DFS to remember to get the next vertex to start a search when a dead end occurs in any iteration.

CRUD operations, Inheritance, and its types.

  1. CRUD operations: CRUD stands for Create, Read, Update, and Delete, and it refers to the basic operations that can be performed on data in a database management system.
a. Create (C) operation: This operation is used to insert new data into the database.
b. Read (R) operation: This operation is used to retrieve data from the database.
c. Update (U) operation: This operation is used to modify existing data in the database.
d. Delete (D) operation: This operation is used to remove data from the database.
  1. Inheritance: Inheritance is a feature of object-oriented programming (OOP) that allows a new class to be created by inheriting properties and behaviors from an existing class. The new class is called the derived class or child class, and the existing class is called the base class or parent class.
    Inheritance is used to create a new class that is a modified version of an existing class, without having to rewrite all the code in the new class. This helps to avoid redundancy, reduce complexity, and improve code maintainability.
    1. Types of Inheritance: There are several types of inheritance in OOP, including:
    a. Single inheritance: This type of inheritance occurs when a derived class inherits properties and behaviors from a single base class.
    b. Multiple inheritance: This type of inheritance occurs when a derived class inherits properties and behaviors from multiple base classes.
    c. Multi-level inheritance: This type of inheritance occurs when a derived class inherits properties and behaviors from a base class, which in turn inherits properties and behaviors from another base class.
    d. Hierarchical inheritance: This type of inheritance occurs when multiple derived classes inherit properties and behaviors from a single base class.
    e. Hybrid inheritance: This type of inheritance is a combination of multiple inheritance types, such as single inheritance, multiple inheritance, and multi-level inheritance.

What is difference between primary key and unique key?

Primary Key
Unique Key
1.     It cannot have NULL value present.
It can have NULL value.
2.     There can be only one primary key in a table.
There can be multiple unique key in a table.
3.     Primary key automatically creates a clustered index.
Unique key creates a non-clustered index. 

What does this mean [::-1]?

The syntax [::-1] is a slice notation in Python and is used to reverse a sequence, such as a list or a string. The slice notation consists of three parts:
  1. The start index: This is the first index of the slice. The default value is 0, which means the slice starts from the first element of the sequence.
  1. he stop index: This is the index at which the slice stops. The default value is -1, which means the slice stops at the last element of the sequence.
  2. The step value: This is the difference between consecutive elements in the slice. The default value is 1, which means the slice includes every element of the sequence.
When the step value is -1, the slice returns the elements of the sequence in reverse order. So, [::-1] returns the elements of the sequence in reverse order, from the last element to the first element.
For example:
>>> my_list = [1, 2, 3, 4, 5]
>>> my_list[::-1]
[5, 4, 3, 2, 1]

Create a server using HTTP

Here is an example of creating a simple HTTP server using the http.server module in Python:
import http.server
import socketserver

PORT = 8080

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("serving at port", PORT)
    httpd.serve_forever()
This code sets up a simple HTTP server that listens on port 8080. The http.server.SimpleHTTPRequestHandler class is used to handle incoming requests and return responses. The server uses the socketserver module to bind to a socket and listen for incoming connections.
When you run this code, the server will start listening on port 8080, and you can access it by opening a web browser and navigating to http://localhost:8080. You should see a directory listing of the current directory, and you can navigate to any files within that directory to see their contents.

Difference between == and ===.

== operand loosely compares two values i.e. it can be used to ignore the datatype of operand.

=== operand strictly compares two values i.e. it is used where datatype of operand is important.

What is the use of Foreign Key?

It is an attribute or a set of attributes that references to primary key of same table or another table.

What are the constraints used in a table?

Constraints are used in a database table to enforce rules and limitations on the data that can be stored in the table. Some common constraints in relational database management systems (RDBMS) include:
  1. NOT NULL constraint: This constraint ensures that a column cannot contain a NULL value. If a NULL value is attempted to be inserted into a column with this constraint, the database will raise an error.
  2. Unique constraint: This constraint ensures that all values in a column are unique, so no duplicates are allowed. If a duplicate value is attempted to be inserted, the database will raise an error.
  3. Primary key constraint: This constraint specifies a column or set of columns as the primary key of a table. The primary key is used to uniquely identify each row in the table, and it cannot contain a NULL value.
  4. Foreign key constraint: This constraint specifies a column or set of columns that refer to the primary key of another table. The foreign key constraint is used to enforce referential integrity between tables, ensuring that data in one table corresponds to data in another table.
  5. Check constraint: This constraint is used to specify a condition that must be met for data to be inserted or updated in the table. The check constraint is used to enforce custom rules and restrictions on data.
  6. Default constraint: This constraint is used to specify a default value for a column. If no value is provided for a column with a default constraint, the default value will be used.
Constraints are used to maintain the integrity and consistency of data in a database, and they are essential for ensuring that the database stores valid and meaningful data.

Nagarro Solved

Automata Fixing

      

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories