Skip to main content

Posts

Showing posts from February, 2023

Fixed Size Window Sliding Problems

  Average Of All Subarrays Given an array, find the average of all subarrays of ‘K’ contiguous elements in it. Let’s understand this problem with real input: Array: [1, 3, 2, 6, -1, 4, 1, 8, 2], K=5 Here is the final output containing the averages of all subarrays of size '5': Output: [2.2, 2.8, 2.4, 3.6, 2.8] Solution def findAverage ( nums , k ):     windowSum = sum ( nums [: k ]) #initilize a window of size k     average = windowSum / k #initialize average for first window     result =[ average ]         for i in range ( len ( nums )- k ): #Loop through the array with less k size         windowSum = windowSum - nums [ i ]+ nums [ i + k ] # subtract last item of previous window and add next item         average = windowSum / k         result . append ( average )     return result

Array Data Structure

What is an Array? An array is a data structure that stores a fixed-size sequential collection of elements of the same type. In other words, an array is a collection of variables of the same type, which are accessed by a common name. Types of Array: One-dimensional array: This is the simplest type of array, where the elements are stored in a single row. Multi-dimensional array: This type of array allows you to store elements in a two-dimensional, three-dimensional, or even higher-dimensional grid. Jagged array: This type of array is an array of arrays, where each element in the array is an array of varying length. Advantages of using Array: Arrays allow for quick and easy access to elements . You can access any element in an array by its index, which makes it easy to manipulate data. Arrays are great for storing large amounts of data in a structured way. You can organize data in an array in a way that makes sense for your program. Arrays are efficient in terms of memory usage , as the...

All about Tree Data Structures

 What is a Tree data structure?  A tree is a non-linear data structure that consists of nodes connected by edges , where each node can have zero or more children nodes . The topmost node of a tree is called the root node , and nodes with no children are called leaf nodes . There are several types of trees: Binary Tree : A binary tree is a tree in which each node has at most two children. Binary Search Tree (BST): A binary search tree is a binary tree in which the left subtree of a node contains only nodes with keys less than the node's key, and the right subtree contains only nodes with keys greater than the node's key. AVL Tree: An AVL tree is a self-balancing binary search tree in which the heights of the left and right subtrees of any node differ by at most one. B-Tree: A B-tree is a self-balancing tree in which each node can have more than two children. Trie: A trie is a tree-like data structure used to store a set of strings, where each node represents a single character...

Top 10 System Design Interview Question Asked by Microsoft and Google

Here are the top 10 system design questions that are frequently asked in Microsoft and Google interviews: Microsoft: Design a web crawler and search engine Design a distributed file system. Design a scalable and highly available message queue system. Design a scalable video streaming service. Design a key-value store database. Design a recommendation engine for an e-commerce platform. Design a fault-tolerant database system. Design a load balancing system. Design a distributed cache system. Design a content delivery network (CDN). Google: Design a search engine. Design a social networking site. Design a scalable and highly available distributed system. Design a real-time analytics system. Design a recommendation system for YouTube. Design a scalable map-reduce system. Design a system for handling petabytes of data. Design a data center network. Design a caching system for frequently accessed data. Design a system to detect and prevent fraudulent activity. ...

Top trending concepts in System Design Interviews.

  Here are some trending topics on system design:   Microservices Architecture: Microservices architecture is a design pattern that structures an application as a collection of small, independent services that communicate with each other using APIs. It allows for more flexibility and scalability, as each service can be updated, deployed, and scaled independently.   Serverless Architecture: Serverless architecture is a design pattern where the application is hosted on third-party servers, and developers don't have to worry about the underlying infrastructure. It is a cost-effective and scalable option for developing and deploying applications.  examples are  Azure Functions and AWS Lambda            Cloud-Native Architecture: Cloud-native architecture is an approach that utilizes cloud computing to build and run applications. It allows for rapid development, deployment, and scaling of applications. There are 3 major platf...

How to answer behavioral questions in an interview?

  The STAR method is a popular approach used in job interviews to answer behavioral interview questions. It is an acronym that stands for Situation, Task, Action, and Result.   Situation: First, describe the situation you were in. This sets the context for the interviewer and provides them with the background information necessary to understand the rest of your answer. Task: Next, explain the task that you needed to accomplish in the situation. This clarifies what you were responsible for and what you were trying to achieve. Action: Then, describe the specific actions you took to address the situation and accomplish the task. This is where you can really highlight your skills and abilities. Result: Finally, explain the outcome of your actions. This is where you can showcase the impact you had on the situation and what you learned from the experience. By using the STAR method, you can provide a clear and structured answer to behavioral interview questions that dem...

Domain Driven Design (DDD) Pros and Cons

  Domain Driven Design   Domain-Driven Design (DDD) is a software development methodology that emphasizes the importance of understanding the domain of a problem before creating a solution. DDD involves collaborating with domain experts and creating a shared language to develop a deep understanding of the problem domain. It also focuses on designing the software around the core business processes and models, rather than around technical concerns.   The benefits of DDD include:   Improved collaboration: By involving domain experts in the development process, DDD fosters collaboration and understanding between developers and domain experts .   Better alignment with business needs : DDD focuses on designing software around core business processes, which helps ensure that the software aligns with the needs of the business . Improved software quality: By focusing on the core business processes and models, DDD helps ensure that the software is more maintainab...

CQRS Pattern

  CQRS (Command Query Responsibility Segregation) is a pattern used in software design to separate the write and read operations of an application. It separates the concerns of commands (write operations) and queries (read operations) into two separate models.   The basic idea behind CQRS is to split the application into two parts: a command side that is responsible for handling the write operations, and a query side that is responsible for handling the read operations. The command side is optimized for transactions and is typically responsible for updating the database. The query side is optimized for querying and is typically responsible for generating reports and presenting data to the user.   Here are the steps to implement CQRS using system design concepts:   Identify the operations: Identify the write and read operations that the system will support.   Design the command side: Design the command side of the application to handle the write operat...

How to improve performance of a system?

There are several ways to improve the performance of a system using system design concepts: Caching: Use caching to reduce the response time for frequently accessed data. This can be done at various levels, such as application-level caching, in-memory caching, and CDN caching.   Load balancing: Use load balancing to distribute the workload across multiple servers or nodes. This can help to improve the throughput and reduce response times.   Database optimization: Optimize the database by using indexing, query optimization, and database replication. This can help to improve the database performance and reduce response times.   Sharding : Use database sharding to horizontally partition data across multiple servers or nodes. This can help to improve scalability and reduce response times.   Asynchronous processing: Use asynchronous processing to offload non-critical tasks to background threads or queues. This can help to reduce response times and improve the...

Database Sharding.

    Database sharding is a technique used in distributed database systems to horizontally partition data across multiple servers or nodes. The goal of sharding is to improve scalability and performance by distributing the data and query load across multiple nodes.   In sharding, data is divided into smaller, more manageable subsets called shards, and each shard is stored on a separate server or node. Each node in the system is responsible for storing and processing a subset of the data. Queries to the database are then distributed across the nodes, with each node processing queries related to its subset of the data.   Benefits of Sharding:   Improved scalability: Sharding allows for horizontal scaling of the database, with additional nodes added to handle increased data and query loads.   Improved performance: Sharding can improve performance by distributing the query load across multiple nodes, reducing the workload on each node.   C...

What is Database replication? Advantages and Limitations of Database Replication.

Database replication is the process of creating and maintaining multiple copies of a database in different locations or on different servers. The purpose of replication is to provide redundancy and improve availability and performance of the database.   In database replication, changes made to the primary or master database are replicated to one or more secondary or replica databases in real-time or near-real-time. This process can be done synchronously or asynchronously, and in different topologies such as master-slave or master-master. Replication can be done within the same data center or across geographically dispersed locations.   Advantages of Database Replication:   Improved availability : Database replication provides redundancy and failover capabilities, ensuring that the database remains available even in the event of a hardware or network failure.   Improved performance : Replication can improve database performance by offloading read queries to ...

What is Rate limiter? Advantages of using Rate Limiter? Limitations of Rate limiting?

  A rate limiter is a mechanism used to control the rate at which requests are sent to a server or an API (Application Programming Interface). It is used to prevent abuse, misuse, or excessive use of a system's resources, and to ensure that a system is able to provide consistent and reliable service to its users.   The main advantages of using rate limiting include:  Preventing abuse : Rate limiting can help prevent malicious attacks or excessive use of a system's resources, such as a Denial of Service (DoS) attack or brute force login attempts. Ensuring service availability: By limiting the rate of incoming requests, rate limiting can help ensure that a system is able to provide consistent and reliable service to its users, even during periods of high traffic.   Managing costs: Rate limiting can help manage costs by limiting the use of expensive resources, such as processing power, network bandwidth, or database queries.   However, there are also s...

Difference Between API Gateway and Load Balancer

  An API Gateway typically operates at the application layer (Layer 7) of the network stack and can provide advanced features such as authentication, rate limiting, caching, and transformation of requests and responses. An API Gateway is used to simplify the management of multiple APIs, ensure security and compliance, and provide a consistent interface for API clients.   In summary, the key differences between an API Gateway and a Load Balancer are:   Function : A load balancer distributes traffic across multiple servers in a system, while an API Gateway manages and routes API requests.   Network layer : A load balancer operates at the transport layer (Layer 4) of the network stack, while an API Gateway operates at the application layer (Layer 7).   Features : A load balancer typically provides basic traffic distribution based on IP addresses and ports, while an API Gateway provides advanced features such as authentication, rate limiting, and caching of ...

What is a Load Balancer ? Why to use it? What are different types of load balancers are available?

  Load balancers are used to improve the performance, availability, and scalability of a system. By distributing incoming traffic across multiple servers, a load balancer can prevent any single server from becoming overloaded, improving overall system performance and reducing downtime. Additionally, load balancers can provide a way to scale a system horizontally, adding more servers to handle increased traffic.   There are several different types of load balancers available, including:   Hardware load balancers: Hardware load balancers are physical devices that sit between the client and the server. They are typically high-performance and offer a range of advanced features, such as SSL offloading, session persistence, and health checks.   Software load balancers: Software load balancers are applications that run on a server, allowing it to act as a load balancer. They are often less expensive than hardware load balancers and can be easier to configure and man...

Caching Key Concepts

  What is Caching? Caching is a technique for storing frequently used data in a fast-access memory, which can improve the performance of a system. The cached data can be retrieved quickly and easily, reducing the time and resources needed to fetch the data from its original source (such as a database or a file system).   Why to use Caching?   Caching is used to reduce the number of requests to the original data source, which can result in improved performance, reduced latency, and increased throughput. Caching can also help to reduce the load on the original data source, leading to improved scalability and lower operational costs.   Types of Caching   There are several different types of caching available, including:   In-memory caching: In-memory caching stores frequently used data in a fast-access memory, such as RAM, for quick retrieval. This can improve the speed and performance of the application by reducing the number of requests to the ...

How to achieve Scalability in a system? or How to scale your system?

Scalability refers to the ability of a system to handle increased loads without experiencing a significant decrease in performance. Achieving scalability can be a complex process and requires careful planning, but here are some common strategies that can help:   Horizontal scaling: Adding more machines to handle increased loads is a popular way to achieve scalability. This can be done by using load balancers to distribute incoming requests to multiple machines, allowing the system to handle more traffic.   Vertical scaling: Adding more resources (e.g., CPU, memory, storage) to a single machine can also increase its capacity to handle more traffic.   Caching: Caching is a technique that stores frequently used data in a fast-access memory, reducing the time required to fetch it from the database or file system. By using caching, a system can reduce the load on its backend components and improve performance.   Distributed architecture: Breaking down a system ...

How to become a better software engineer?

 Becoming a software engineer is a dream of many IT aspirant, but if you would like to become a better at Software Engineering , You would need to follow these tips sooner or later in your career. Learn and master at-least one programming language like Python/Java or C# :  Well that's obvious, if you want to become a programmer you would at-least need to learn one programming language specially Object oriented programming language, but Mastering one is more important to crack interviews and solve real world problems. Learn Data Structures and Algorithms:  Believe me you will thank me later if you learn DSA as early as possible in your career,  Because more you get experienced more you will regret not learning DSA in the beginning of your career  when you will see your colleagues and batch mates will be growing by having DSA as a skill. Learn System Design Fundamentals:  Some people thinks System design is for experienced professionals, but it is i...