Join Regular Classroom : Visit ClassroomTech

Slice Overall Interview Questions – codewindow.in

Hot Topics

Slice Solution

Technical Round

What is ARC?

ARC stands for Automatic Reference Counting, a memory management technique used in Apple’s Objective-C and Swift programming languages. ARC automatically tracks and manages the lifecycle of objects in memory, freeing up memory when it is no longer needed to avoid leaks and improve performance. With ARC, developers do not need to manually manage memory as they do in languages like C, but can still achieve efficient and reliable memory management.

What is GCD?

The greatest common divisor (GCD) of two or more numbers is the greatest common factor number that divides them, exactly. 

Improve swiggy delivery.

Tell about your ideas how to improve swiggy delivery.

Improve the weather forecast app

Tell about your ideas how to improve Improve the weather forecast app.

Print number of substrings of a string with given K unique characters.

#include <iostream>
#include <unordered_map>
using namespace std;

int countSubstrings(string s, int k) {
    int n = s.length();
    int res = 0;
    for (int i = 0; i < n; i++) {
        unordered_map<char, int> m;
        int unique = 0;
        for (int j = i; j < n; j++) {
            if (m[s[j]]++ == 0) {
                unique++;
            }
            if (unique == k) {
                res++;
            }
            if (unique > k) {
                break;
            }
        }
    }
    return res;
}

int main() {
    string s = "abcba";
    int k = 2;
    cout << countSubstrings(s, k) << endl;
    return 0;
}
/*
output:
2
*/

How will you set up a bank in tier 2 city? Explain the steps with reason.

Setting up a bank in a tier 2 city involves the following steps:
  1. Obtain regulatory approvals: This is the first and most important step. You need to obtain all necessary licenses and approvals from the central bank and other regulatory bodies to operate as a bank in the region.
  2. Conduct market research: Before starting the bank, it is important to have a clear understanding of the market you are entering, including the local economy, customer demographics, and competition. This research will help you to make informed decisions about the products and services you will offer, as well as the target market you want to serve.
  3. Choose a location: The location of your bank will impact the accessibility and visibility of your bank to potential customers. Select a location that is easily accessible, visible and has a good footfall of people.
  4. Hire staff: Hire experienced staff who have a good understanding of the banking sector and local market conditions. This will ensure that the bank operates efficiently and effectively.
  5. Set up infrastructure: Set up the necessary infrastructure, including physical branches, technology, and systems that are necessary for the bank to operate. This includes setting up computer systems, internet connectivity, telecommunication systems, and an ATM network.
    1. Develop a business plan: A well-structured business plan should be in place that outlines the objectives, target market, products and services offered, and the marketing strategy for the bank.
    2. Raise capital: A sufficient amount of capital is required to start the bank. You can raise capital through equity offerings, loans, or partnerships.
    3. Marketing and customer acquisition: Market the bank to attract new customers and retain existing ones. Develop customer acquisition and retention programs to increase customer loyalty.
    In conclusion, setting up a bank in a tier 2 city requires careful planning and execution. By following these steps, you can ensure that your bank is set up for success and can serve the financial needs of the local community.

Find the number of nodes that are at a distance k from leaf nodes in a binary tree.

To find the number of nodes that are at a distance k from leaf nodes in a binary tree, you can follow these steps:
  1. Perform a depth-first search (DFS) on the binary tree.
  2. Start from the leaf nodes and mark the nodes that are at a distance k from the leaf nodes.
  3. Keep track of the count of such marked nodes.
  4. Repeat the above steps for all the leaf nodes in the binary tree.
  5. Return the count of marked nodes as the result.
The reason for performing a DFS is that it helps in traversing the entire tree and exploring the nodes at a given distance from the leaf nodes. By marking the nodes, we keep track of the count of nodes that are at a distance k from the leaf nodes.

Find the maximum number of partitions which when sorted individually, sorts the whole array.

To find the number of nodes that are at a distance k from leaf nodes in a binary tree, you can follow these steps:
  1. Perform a depth-first search (DFS) on the binary tree.
  2. Start from the leaf nodes and mark the nodes that are at a distance k from the leaf nodes.
  3. Keep track of the count of such marked nodes.
  4. Repeat the above steps for all the leaf nodes in the binary tree.
  5. Return the count of marked nodes as the result.
The reason for performing a DFS is that it helps in traversing the entire tree and exploring the nodes at a given distance from the leaf nodes. By marking the nodes, we keep track of the count of nodes that are at a distance k from the leaf nodes.

Right View of a binary tree.

The right view of a binary tree is the set of nodes visible from the right side of the tree. To traverse the right view of a binary tree, one approach is to perform a level-order traversal and keep track of the last node in each level. As we traverse each level from left to right, we will only add the last node in each level to the result list, as it is the only node visible from the right side of the tree. This can be implemented using a queue to store nodes at each level, and a variable to keep track of the current level. The algorithm is as follows:
  1. Initialize a queue and add the root node to it.
  2. Initialize a result list to store the right view of the binary tree.
  3. Loop until the queue is empty: a. Get the size of the queue and store it in a variable, let’s call it size. b. Loop over the size of the queue and remove each node, adding it to the result list if it is the last node in the level. c. If the current node has a left child, add it to the queue. d. If the current node has a right child, add it to the queue.
  4. Return the result list.
This algorithm has a time complexity of O(n), where n is the number of nodes in the binary tree.

Difference between MySQL and PostgreSQL.

MySQL
PostgreSQL
1.    MySQL is just a relational database management system.
PostgreSQL is an object based relational database management system.
2.    MySQL Workbench is used.
PgAdmin is used.
3.    Troubleshooting is easy in MySQL.
Troubleshooting is difficult in PostgreSQL.
4.    MySQL was built using C/C++ language.
PostgreSQL was built implementing C language.
5.    MySQL supports standard data types
PostgreSQL supports advance data types like arrays, user-defined types, etc.
 

Difference between the Adapter pattern and the Factory pattern. 

The Adapter pattern is a structural design pattern that allows objects with incompatible interfaces to work together. It converts the interface of a class into another interface that the client expects.
The Factory pattern is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
In simple words, the Adapter pattern allows two incompatible objects to communicate, while the Factory pattern is used to create objects without specifying the exact class of object that will be created.

Write an algorithm to do in place merging function for merge sort.

Here is an algorithm for in-place merging of two sorted arrays using the merge sort approach:
  1. Start with two arrays, A and B, which are already sorted.
  2. Initialize two pointers, i and j, to point to the start of the arrays A and B respectively.
  3. While both pointers i and j are less than the lengths of arrays A and B, compare the elements pointed to by i and j.
  4. If the element pointed to by i is smaller, increment i to point to the next element in array A.
  5. If the element pointed to by j is smaller, move the element pointed to by j to the current position of i in array A and increment j to point to the next element in array B.
  6. Repeat the above steps until either the pointer i reaches the end of array A or the pointer j reaches the end of array B.
  7. If the pointer j has not reached the end of array B, move the remaining elements of array B to the end of array A.
  8. The final array A will contain all the elements of both arrays A and B, sorted in ascending order.
This algorithm performs the merge operation in-place, without using any additional storage.

The two arrays in a normal merge sort algorithm should be a=rearranged without any additional space such that each of the arrays are sorted and last element of first array is smaller than first element of 2nd array

Here is an updated algorithm for in-place merging of two arrays in a normal merge sort algorithm:
  1. Start with two arrays, A and B, which are already sorted.
  2. Rearrange the arrays A and B in-place, without using any additional space, such that the last element of the first array is smaller than the first element of the second array.
  3. Initialize two pointers, i and j, to point to the end of arrays A and B respectively.
  4. While both pointers i and j are greater than or equal to 0, compare the elements pointed to by i and j.
  5. If the element pointed to by i is larger, decrement i and store the value of the element pointed to by i at the end of array B.
    1. If the element pointed to by j is larger, decrement j and store the value of the element pointed to by j at the end of array A.
    2. Repeat the above steps until either the pointer i reaches the start of array A or the pointer j reaches the start of array B.
    3. If the pointer i has not reached the start of array A, move the remaining elements of array A to the start of array B.
    4. The final array B will contain all the elements of both arrays A and B, sorted in ascending order.
    This algorithm performs the merge operation in-place, without using any additional storage.

Types of joins in SQL. Difference between Full join and Self join.

Types of JOINs:

  • Left Join
  • Right Join
  • Inner Join
  • Full Join
  • Self Join
A Full join and a Self join are both types of joins used in SQL to combine data from two or more tables.
  1. Full join: A Full join returns all the rows from both tables, including the matching and non-matching rows. If a row in one table doesn’t have a matching row in the other table, the result set will contain NULL values for the columns of the non-matching table.
  2. Self join: A Self join is a regular join, but the table is joined with itself. In a Self join, a table is joined with a copy of itself to compare the rows within the same table. It’s useful for finding relationships within a single table, such as finding pairs of rows with similar data.
In summary, a Full join returns all the rows from both tables, while a Self join returns only the matching rows within a single table.

Nagarro Solved

Automata Fixing

      

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories