# Welcome to AOneCode

## Overview

If you want to get hired as software developer at Google, Amazon, Meta and other top tech companies, we boost you up.

## 1v1 Algorithm Courses

**Google/FB Senior Engineer** Private **One-to-One Only** live class.\
&#x20;**7 \* 24 online Q & A.**\
&#x20;Any questions directly ask Google/Meta senior engineers.\
&#x20;Choose the topics you like to learn.\
&#x20;Bring questions to the class.

[Program1: Algorithm Class](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures#program-1)\
[Program2: Advanced Algorithm Class](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures#program-2)\
[Program3-1: Coding Practice Class](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures#program-3)\
[Program3-2: Interview Questions Practice(Recommended before the interview)](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures#program-3)\
[System Design](https://aonecode.com/grokking-the-system-design-interview)\
[Mock Interview](https://aonecode.com/coding-mock-interview)\
Resume Review/Buildup\
And all above included ---- our [Long Term Program](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures#long-term-program). Give us 3-6 month and we land you an offer at FAANG.\
Best financial investment ever!

{% embed url="<https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures>" %}

## 1v1 System Design Courses

**Google/Amazon/Meta&#x20;**<mark style="color:red;">**12+ YOE Engineer**</mark> Private **One-to-One Live** class.\
**Live Class Only. No recording.**\
&#x20;7 \* 24 online Q & A.\
Any questions directly ask Google/Amazon/Meta 12+ Year Of Experience Engineers.\
Resume development.\
Mock Interviews with the real interviewer.

{% embed url="<https://aonecode.com/grokking-the-system-design-interview>" %}

## 1v1 Career Service

Resume/Career Consulting

[Full-stack Development Projects](https://aonecode.com/code-development-programs)

[DS and Algorithms](https://aonecode.com/the-coding-interview-bootcamp-algorithms-data-structures)

[System Design](https://aonecode.com/grokking-the-system-design-interview)

Mock Interviews (Google, Amazon, Uber, Meta...)

We have authored several pieces on algorithm and system design. Keep an eye as we'll be posting new articles on a weekly basis.

[Algo Workshop](/algo-workshop/how-to-solve-different-types-of-dp-problems-asked-in-coding-interviews)

[System Design Pro](/system-design-pro/essential-system-design-10-key-questions-and-answers-on-cdns)


# How To Solve Different Types Of DP Problems Asked In Coding Interviews

How To Solve Different Types Of DP Problems Asked In Coding Interviews

How to solve different types of DP problems asked in coding interviews?&#x20;

This article is for folks beginning on advanced algorithm study (post-college DSA);&#x20;

or anyone who used to solve DP problems after DP problems without really it clicking in their head, who would see a solution and wonder "how the heck did they come with that solution..."&#x20;

Dynamic Programming is one of the most asked problem types in coding interviews for the reasons:

<figure><img src="https://d2qikg3rnxq7n1.cloudfront.net/interviewquestions/645-dp1-org.png" alt="How To Solve Different Types Of DP Problems Asked In Coding Interviews"><figcaption></figcaption></figure>


# Six Must-Do Dynamic Programming Patterns

How to solve different types of DP problems asked in coding interviews? In this article, we will explore six must-do dynamic programming patterns that are commonly used to solve a wide range of problems...

<figure><img src="https://d2qikg3rnxq7n1.cloudfront.net/interviewquestions/69-dp-feed2-org.png" alt="Six Must-Do Dynamic Programming Patterns"><figcaption></figcaption></figure>


# Essential System Design: 10 Key Questions and Answers on CDNs

## When to use a CDN?

1. Global Reach: If your website or application has users from all over the world, a CDN can greatly improve your service's speed and reliability. CDNs have servers located globally and they serve content from the server closest to the user, reducing latency and improving load times.
2. Improved Load Times: A CDN stores a cached version of your website in multiple geographical locations around the world, known as "points of presence" (PoP). When a user requests your site, the CDN redirects the request to the server geographically closest to them. This reduces the distance the data has to travel, thereby reducing latency and improving site load times.
3. Absorb traffic: CDNs are designed to absorb sudden spikes in web traffic. This is particularly important for websites that experience variable traffic, ensuring your website remains accessible and provides a good user experience even during peak times.
4. Reduced Bandwidth Costs: CDNs can significantly reduce the amount of data an origin server must provide by caching and optimizing files, thus reducing hosting costs.
5. Always Online: Increased Content Availability and Redundancy. If one server fails, CDNs can automatically reroute the traffic to the next nearest server. This ensures high availability and reliability, even in the event of a server failure or DDoS attack.
6. Improved Website Security: CDNs provide a layer of protection against malicious attacks such as Distributed Denial of Service (DDoS) attacks. They also offer SSL/TLS encryption and other security features to ensure data integrity and privacy.
7. Software Distribution: Companies that distribute software or updates to a global user base can use a CDN to ensure quick and reliable downloads. This is particularly important for operating system updates, antivirus software, and other applications where timely updates are crucial.
8. Media Streaming: For websites or applications that stream video or audio content, CDNs are vital. They ensure smooth, buffer-free streaming for users, regardless of their location.
9. Live Events: For live online events like concerts or sports, a CDN can handle the sudden influx of users and provide a seamless viewing experience, free of buffering or lag.

## When not to use a CDN:

1\. **Small Audience or Limited Geographic Reach**: If your website's audience is small or primarily located in a single geographic location (near to your hosting server), a CDN may not provide much benefit and might not be worth the cost.

* **A local restaurant's website**

  A small restaurant that serves a local community and whose patrons are all from the same city wouldn't benefit much from a CDN. The website's traffic levels would be relatively low, and all visitors would be geographically close to the hosting server.
* **An intranet application for a single office location**

  If a company builds an internal application used exclusively by employees at a single office location, a CDN would not offer much advantage. All users are accessing the application from the same location, so the latency benefits of a CDN would not be realized.

2\. **Dynamic, Non-cacheable Content**: CDNs are best at delivering static, cacheable content (like images, CSS, JavaScript, and HTML files). If your site or application primarily serves dynamic, non-cacheable, or personalized content, you may not see a significant performance improvement with a CDN.

* **A financial app dealing with real-time data**

  If an app deals primarily with dynamic, real-time data (like a stock trading app), a CDN may not be very beneficial. CDNs are most effective at caching and serving static content, so they might not significantly improve performance for an application like this. In such a scenario, it would be more beneficial to focus on optimizing server performance and database queries.

3\. **Data Privacy and Compliance**: In some cases, strict data privacy regulations or compliance requirements might limit your ability to distribute data across various geographic locations. In such cases, using a CDN may pose regulatory challenges.

* **A healthcare portal with strict data privacy requirements**

  To ensure patient data confidentiality, a healthcare portal concerned about data leaks would opt against using a CDN. By relying solely on internal servers and infrastructure, they can maintain strict control over data access and minimize the risk of unintended data exposure that could arise from utilizing a CDN with distributed servers.

## Do you know CDN's standard internal infrastructure?

The choice of infrastructure architecture plays a vital role in defining a CDN's product identity and determining the value it brings. At the core of CDN infrastructures are PoPs (points of presence) which are regional data centers responsible for interacting with users in close proximity.

> What is PoP house? Typically, each PoP houses multiple servers and routers that handle caching, connection optimization, and other content delivery features. For CDNs that offer security solutions, PoPs also house DDoS scrubbing servers and machines dedicated to other security-related functions.

How to reduce round-trip time, boosting website speed and responsiveness? Regional distribution centers. By utilizing regional content distribution centers, the round-trip time (RTT) is significantly reduced, resulting in a faster and more responsive website for visitors, regardless of their location.

> Round-trip time (RTT) refers to the duration, measured in milliseconds (ms), it takes for a browser to send a request and receive a response from a server. RTT is not influenced by file size or internet connection speed but is determined by factors such as physical distances, the number of intermediate nodes, amount of traffic, and transmission mediums. RTT plays a crucial role in determining the speed of rendering in the user's browser, as the rendering cannot commence until the initial request for the HTML file is returned.

## What's Alternatives of CDN?&#x20;

During a system design interview, when seeking ways to enhance website speed and responsiveness, CDN is the first solution that comes to mind. However, there are other alternatives worth considering, such as <mark style="color:blue;">Carrier-Neutral Data Centers</mark> and <mark style="color:blue;">Mirror Sites</mark>. These alternatives can also play a significant role in improving website performance.

## CDN vs Carrier-neutral Data Centers?

> A carrier-neutral data center is a facility that provides interconnection to multiple third-party network service providers (carriers) and/or internet service providers (ISPs). The carrier neutrality of the facility ensures that clients have a choice of connectivity options, and it encourages competition between the various providers, which can lead to better pricing and service quality for the end-users.

Common carrier-neutral data centers do address the issue of slow access between different ISPs, but this solution requires relinquishing some control and introducing an additional layer of dependency into the system.

However, using a CDN can provide a more flexible and customizable solution. For instance, given that CDN nodes are distributed across a range of ISPs, connection data can be retrieved to ensure better routing. Moreover, the traffic distribution principle of a CDN inherently equips it with the ability to resist network attacks."

## CDN vs Mirror Sites?

> A mirror site is a replica of an already existing website, containing identical or near-identical content, but hosted on a different server and often under a different domain name.

CDN is entirely transparent to the website's visitors; there's no need for visitors to manually select the mirror site they want to visit, ensuring a friendly user experience. CDN performs availability checks on each node, excluding any nodes that don't meet the standards promptly, thus guaranteeing high availability - something that mirror sites can't achieve. Deploying CDN is simple and generally doesn't require any changes to the original site to take effect.

## Does CDN acceleration apply to the server or to its domain name?

CDN accelerates a specific domain name of a website. If a website has multiple domain names, visitors accessing the domain name with CDN will experience the acceleration effect, but those accessing non-CDN domain names, or directly accessing the IP address, will not experience the CDN effect.

## How to setup the CDN?&#x20;

Setting up a CDN is typically a seamless process that can be accomplished with just a few clicks on the dashboard. No modifications are generally required for the origin website to harness the acceleration benefits of the CDN. However, minor adjustments may be necessary for software reliant on visitor IP identification.

## Have you ever experienced the issue of outdated data persisting via a CDN even after deploying new content? How to troubleshoot and resolve this issue?

Due to CDN's caching mechanism across various nodes, static webpages and images might remain unchanged if CDN cache isn't updated correspondingly after modifications are made, leading to old webpages being displayed. To resolve this, the CDN provider always provides a URL purge service to notify all CDN nodes to refresh their cache. By entering specific webpage or image addresses in the URL purge bar, cache content on all nodes will be deleted uniformly and take effect immediately. If there are too many URLs and images to purge, directory and regex based purging can be chosen.

Also the CDN caches may at different levels, including the CDN edge servers, the user's browser, and possibly intermediary proxies, can store outdated content and serve it instead of the updated version. To optimize CDN caching, consider two key steps:

1. Configure cache control headers.&#x20;
2. Set CDN TTL properly.

## Can CDNs be configured to avoid caching web pages and images that require frequent real-time updates?

Some web pages and images may need to be updated frequently or in real time, such as news articles, stock prices, or live streams. In these cases, caching them on a CDN may result in outdated or inaccurate information being delivered to the users. Therefore, it is possible to configure a CDN not to cache certain web pages and images that require high real-time updates.

This can be done by using HTTP headers, such as Cache-Control or Expires, to instruct the CDN servers how long to store the web content before requesting a fresh copy from the origin server. For example, if a web page contains a live stream of a sports event, it can use the Cache-Control header with the value "no-cache" or "max-age=0" to prevent the CDN from caching it at all. Alternatively, some CDN providers may offer more granular control over the caching behavior, such as allowing the users to specify which URLs or file types to exclude from caching, or using dynamic tokens or signatures to validate the freshness of the web content.

Another option is to leverage Edge Side Includes (ESI) if supported by the CDN. ESI tags allow dynamic inclusion of specific parts within a web page while still benefiting from CDN caching. By isolating frequently updated sections within ESI tags, only those sections bypass caching while the CDN caches the remaining parts of the page, ensuring real-time updates for the specified sections.

Alternatively, one website could use two domain names: one enabled with CDN and the other without, and pages and images requiring real-time updates can be placed under the domain without CDN.


# Quickly Comprehend Persistent Connections And The Heartbeat Mechanism

Quickly Comprehend Persistent Connections and the Heartbeat Mechanism

{% hint style="info" %}

### **Non-Persistent Connections**

First let's have a look at what is Non-Persistent Connections:\
Non-persistent connections involve a single request-response cycle between a client and a server, and are suitable for applications with numerous short transactions.

What's the lifecycle of the Non-Persistent Connections:\
1\) Client and server establish a connection via a three-way handshake.\
2\) Client sends a request message, server responds.\
3\) Connection is closed.
{% endhint %}

{% hint style="info" %}

### **Persistent Connections**

Then what's the Persistent Connection?\
In persistent connections, the client and server maintain an open connection for multiple read/write operations.

**Lifecycle**

1\) Client initiates connection, server accepts.\
2\) Connection remains open until requested to close or abnormal situations occur.\
3\) Can last for long periods of time (days, months, years).
{% endhint %}

## **What's the Pros and Cons**

**Non-Persistent Connections:**

Pros:\
Resource efficiency: Non-persistent connections release resources when the connection is closed, reducing the overall load on the server.\
Suitable for short transactions: They are well-suited for applications with a large number of short, sporadic transactions, as they do not consume resources after the transaction is complete.

Cons:\
Increased overhead: Establishing and closing connections for each request-response cycle can consume additional resources, impacting performance.\
Slower for frequent transactions: Applications requiring rapid, continuous transactions may experience slower performance due to the overhead involved in establishing and closing connections.

\
**Persistent Connections:**

Pros:\
Reduced overhead: Since the connection remains open for multiple requests, it saves the time and resources required for establishing and closing connections.\
Improved performance: The reduced overhead can lead to faster response times for applications that involve frequent and continuous data exchange.\
Better error handling: Persistent connections allow for error prompts without needing to close the connection.

Cons:\
Resource consumption: Persistent connections consume server resources, as they remain open even when not actively transmitting data.\
Scalability issues: A large number of open connections can impact server performance and limit concurrency.

\
**Use Cases**
-------------

### **Non-Persistent Connection**

Simple Data Requests: Non-persistent connections are commonly used in applications where simple data requests are required, such as a user making a single query to a search engine.

Low Traffic Applications: Applications with low traffic, such as personal blogs, may not require a persistent connection as the number of requests is low.

Limited Resources: Non-persistent connections are used in applications that have limited resources, such as mobile devices, to minimize the number of connections that need to be maintained.

File Downloads: Non-persistent connections are commonly used in file download applications where users download files intermittently.

One-Time Transactions: Non-persistent connections are useful for one-time transactions, such as completing an online purchase, where the user makes a single request and then disconnects.

### **Persistent Connection**

Database Connectivity: Persistent connections are used to maintain database connections in applications such as web servers, where a large number of requests are received simultaneously.

Real-Time Communication: Persistent connections are useful in real-time communication applications such as video conferencing, voice over IP (VoIP), and instant messaging. In these applications, it is necessary to maintain a continuous connection between the client and server for the duration of the communication.

Streaming Services: Persistent connections are widely used in streaming services such as Netflix and Spotify, where a continuous stream of data is required.

WebSockets: Persistent connections are also used in WebSockets, a communication protocol that enables two-way communication between a client and a server over a single TCP connection.

Online Gaming: Persistent connections are used in online gaming applications to maintain real-time communication between players and the game server.

Internet of Things (IoT): Persistent connections are useful in IoT applications, where a large number of devices need to communicate with the server continuously.

Remote service calls (RPC) between servers.

\
**Heartbeat Mechanism in the Persistent Connection**
----------------------------------------------------

### **Introduction**

A Heartbeat mechanism is used to maintain persistent connections by regularly sending data packets between the client and server.

<div align="left"><figure><img src="/files/mrzgBOy1Rgk8Miz0pjs5" alt="" width="317"><figcaption></figcaption></figure></div>

### **Why is it needed?**

To detect and maintain the connection's availability, prevent data loss, and ensure reliable communication between the client and server.\
In a persistent connection, the client and server keep the connection open for an extended period of time, even when there is no data being transmitted. During this period, network disruptions or equipment failure can cause the connection to be lost, resulting in data loss or other issues.\
For example, during unreliable networks can cause connection interruptions, and a Heartbeat mechanism helps detect offline clients or servers quickly.

**How it works**\
The Heartbeat Mechanism sends periodic messages from the client to the server to check whether the connection is still active. These messages are typically small and contain no useful data, but their purpose is to ensure that the connection remains open and active.\
If the server does not receive a heartbeat message within a specified time period, it assumes that the client is no longer active and closes the connection. This process helps prevent data loss and ensures that the connection remains available for use when it is needed.

**Config the TCP KeepAlive**\
The default state for KeepAlive is closed, and it can be turned on by the TCP settings. Additionally, you can tune the keepalive time,which represent the idle time before sending a KeepAlive ACK packet.\
Also the keep alive probes,the number of ACK packets sent before considering the other side disconnected.\
And also even the interval for the pings, the time between two ACK packets

**Needs attention**\
Many network devices, especially NAT routers, cannot maintain all connections on them due to hardware limitations such as memory and CPU processing power.\
Therefore, they may drop some inactive connections in the connection pool when necessary.\
Here is the "algorithm questions" come into the picture.&#x20;

{% hint style="info" %}
Do you know actually you can use LRU(Least Recently Used) to drop the longest inactive connection.\
How about write this code and email us your solution 😀 &#x20;
{% endhint %}

How to solve this problem? Let your TCP connections work properly no matter what the underneath routers or networks?\
One solution is by using TCP's KeepAlive mechanism and config properly, ACK packets can be generated at regular intervals to reduce the risk of being dropped, but this comes at the cost of additional network and CPU load.

### **How to Implement a Heartbeat Mechanism?**

There are mainly two ways to implement a Heartbeat mechanism:

Option1: Directly use the build-in TCP KeepAlive mechanism.\
Option2: Implement a custom Heartbeat mechanism based on the business logic at the application layer.

The pros for option1:\
Using the TCP KeepAlive mechanism is more efficient in terms of traffic consumption than implementing a custom application-layer Heartbeat mechanism.

The disadvantages for the option1:\
Although the TCP protocol layer provides KeepAlive mechanisms, using it has several disadvantages:

1\) It is turned off by default.

2\) The TCP KeepAlive mechanism depends on the operating system's implementation, and the default heartbeat interval is two hours. Modifying the KeepAlive mechanism requires a system call or adjustment to the system configuration, which makes it less flexible and requires additional engineering effort. This modification also introduces more dependencies and potential failure points for the system, making it more challenging to debug.

3\) The TCP KeepAlive mechanism is tightly bound to the TCP protocol. Therefore, if it needs to be replaced with the UDP protocol, the KeepAlive mechanism will be invalid.

The pros and cons for option2? Stay tuned for the next article: Persistent Connections for your Design Interview Part II

<br>


# Must-Know System Design Tips

A system design interview guide from entry-level to senior

<figure><img src="/files/lG7X4AuVXWtWERfAsjeP" alt=""><figcaption></figcaption></figure>

### What is the architecture of the system?

The architecture of the system is typically designed to balance performance, scalability, and security requirements. It may include multiple layers of caching, load balancing, and failover mechanisms to ensure that requests are distributed evenly across multiple servers and that data is stored and retrieved efficiently.

###

### How are requests handled?

Requests are typically handled by the system's request handler, which listens for incoming requests and dispatches them to the appropriate server or service. The request handler may also handle load balancing and failover mechanisms to ensure that requests are distributed evenly across multiple servers.

###

### How are requests distributed across multiple servers?

Requests are typically distributed across multiple servers using a load balancing mechanism, which distributes incoming requests evenly across all available servers. The load balancer may also monitor the health of each server and route requests to healthy servers only.

###

### How are requests stored and retrieved?

Requests are typically stored and retrieved from a database or cache using a key-value store or a cache provider. The key-value store or cache provider may use a distributed cache to store and retrieve data efficiently across multiple servers.

###

### How is data stored and retrieved?

Data is typically stored and retrieved from a database or cache using a key-value store or a cache provider. The key-value store or cache provider may use a distributed cache to store and retrieve data efficiently across multiple servers.

###

### How is security implemented?

Security is typically implemented using a combination of authentication, authorization, and encryption mechanisms. The system may use SSL/TLS to encrypt data in transit, and may also use encryption at rest to protect sensitive data. The system may also use rate limiting and other security mechanisms to prevent attacks and ensure that the system is secure.

###

### How is load balancing implemented?

Load balancing is typically implemented using a load balancer or a reverse proxy. The load balancer or reverse proxy may distribute incoming requests evenly across all available servers, and may also monitor the health of each server and route requests to healthy servers only.

###

### How is fault tolerance implemented?

Fault tolerance is typically implemented using redundancy and failover mechanisms. The system may use multiple servers to ensure that requests are distributed evenly across all available servers, and may also use failover mechanisms to switch to a backup server if a server fails.

### How is scalability implemented?

Scalability is typically implemented using a combination of horizontal and vertical scaling techniques. The system may use a scaling strategy that adds or removes servers based on demand, or it may use a scaling strategy that adjusts the resources allocated to each server based on demand.

### How is performance optimized?

Performance optimization is typically implemented using a combination of caching, compression, and other techniques. The system may use caching to store frequently accessed data in memory, and may also use compression to reduce the size of data that is transmitted over the network.

### How is monitoring and logging implemented?

Monitoring and logging are typically implemented using a monitoring system and logging framework. The monitoring system may monitor the health of each server, the performance of each server, and the overall performance of the system, and may generate alerts or notifications if any of these metrics exceed a certain threshold. The logging framework may log all requests and responses, as well as other relevant information, to help diagnose and troubleshoot issues.

### How is documentation and support provided?

Documentation and support are typically provided through a user manual, a help desk, and a knowledge base. The user manual may provide detailed instructions on how to use the system, including how to navigate the user interface, how to perform common tasks, and how to report issues. The help desk may provide support for users who encounter issues with the system, and may also provide training on how to use the system effectively. The knowledge base may provide detailed information on how the system is designed, how it works, and how to troubleshoot issues.

### How is the system designed for scalability and performance?

The system is designed for scalability and performance by using a combination of caching, load balancing, and other techniques. The system may use a caching provider to store frequently accessed data in memory, and may also use a load balancer to distribute incoming requests evenly across all available servers. The system may also use a scaling strategy that adds or removes servers based on demand, or it may use a scaling strategy that adjusts the resources allocated to each server based on demand.

### How is the system designed for security and reliability?

The system is designed for security and reliability by using a combination of authentication, authorization, and encryption mechanisms. The system may use SSL/TLS to encrypt data in transit, and may also use encryption at rest to protect sensitive data. The system may also use rate limiting and other security mechanisms to prevent attacks and ensure that the system is secure. The system may also use redundancy and failover mechanisms to ensure that the system is resilient to failures.

### How is the system designed for maintainability and evolution?

The system is designed for maintainability and evolution by using a modular architecture that allows for easy customization and extension. The system may use a microservices architecture to break the system into smaller, independent services that can be developed, tested, and deployed independently. The system may also use a version control system to track changes to the code and documentation, and may use automated testing

<figure><img src="/files/l645OLs8aPhaTHKkxbd9" alt=""><figcaption></figcaption></figure>

### Frugal Streaming

Frugal Streaming is a technique used to approximate the results of a query over a data stream, while using minimal memory. It is often used in scenarios where the data stream is too large to fit into memory, but approximate results are acceptable. One example of Frugal Streaming is the Count-Min Sketch algorithm, which uses a fixed-size array of counters to estimate the frequency of items in a data stream. Each item is hashed to a set of counters, and the minimum count in that set is incremented. The estimate for the frequency of an item is the minimum count across all sets.&#x20;

### Leaky bucket / Token bucket:&#x20;

Leaky bucket and Token bucket are two algorithms used for traffic shaping and rate limiting in computer networks. The Leaky bucket algorithm regulates the rate at which data is transmitted by imposing a constant rate of data removal from a buffer. Any data that arrives in excess of the rate is discarded. The Token bucket algorithm regulates the rate at which data is transmitted by issuing tokens at a fixed rate. Each token allows a fixed amount of data to be transmitted. If there are no tokens available, data transmission is blocked.&#x20;

### Loosy Counting

Loosy Counting is a technique used to estimate the frequency of items in a data stream, while using minimal memory. It is similar to Frugal Streaming, but allows for a small amount of error in the estimates. One example of Loosy Counting is the HyperLogLog algorithm, which uses a fixed-size array of registers to estimate the number of distinct items in a data stream. Each item is hashed to a register, and the maximum number of leading zeros in the binary representation of the register values is used to estimate the number of distinct items.&#x20;

### Operational transformation

Operational Transformation is a technique used to synchronize the state of a shared document or data structure across multiple clients in a distributed system. It is often used in collaborative editing applications, such as Google Docs. Operational Transformation works by transforming the operations performed by each client into a common form that can be applied in any order without affecting the final state of the document. This allows each client to see the changes made by other clients in real-time, while ensuring that the final state of the document is consistent across all clients.&#x20;

### Reverse index

Reverse index, also known as an inverted index, is a data structure used to index and search text documents. It works by creating an index of all the words in the documents, along with a list of the documents that contain each word. This allows for efficient searching of documents based on the words they contain. Reverse index is used in many applications, such as search engines and document management systems.&#x20;

### Rsync algorithm&#x20;

Rsync is a file synchronization algorithm used to efficiently transfer files between two systems over a network. It works by comparing the contents of the files on both systems and transferring only the differences between them. This can greatly reduce the amount of data that needs to be transferred, especially for large files or files that have only small changes. Rsync is commonly used for backups and for transferring large files over the internet.&#x20;

###

### Geohash / S2 Geometry

Geohash and S2 Geometry are two related techniques used to represent and index geographic locations on a two-dimensional surface, such as a map. Geohash is a hierarchical spatial data structure that uses a string of characters to represent a location. Each character in the string represents a subdivision of the space, with longer strings representing smaller subdivisions. S2 Geometry is a library for manipulating geometric shapes on the surface of a sphere, such as the Earth. It uses a hierarchical grid system to partition the surface of the sphere into cells of varying sizes. Both Geohash and S2 Geometry are useful for indexing and querying large datasets of geographic locations.&#x20;

###

### Quadtree / Rtree:

Quadtree and Rtree are two related spatial data structures used for indexing and querying two-dimensional data, such as points, lines, and polygons. Quadtree is a hierarchical data structure that recursively subdivides a two-dimensional space into four quadrants, with each quadrant represented by a node in the tree. Rtree is a similar data structure that uses a hierarchical tree of rectangles to represent the data. Both Quadtree and Rtree are useful for spatial indexing and querying in applications such as geographic information systems and computer graphics.&#x20;

### &#x20;

### Ray casting

Ray casting is a technique used to render three-dimensional scenes in computer graphics. It works by tracing rays from the viewer's eye through each pixel in the image plane and into the scene. The rays are tested for intersections with objects in the scene, and the color of the pixel is determined based on the properties of the closest object. Ray casting is a computationally intensive process, but can produce high-quality images with realistic lighting and shading effects.&#x20;

###

### Trie

A Trie, also known as a prefix tree, is a tree-like data structure used to store and retrieve strings efficiently. Each node in the tree represents a prefix of one or more strings, and the edges represent the characters that can follow the prefix. Tries are useful for applications such as autocomplete and spell checking, where fast string lookups are required.


# Mastering The FAANG Coding Interview: How The Grading System Works?

Do you know how FANG grades coding interviews for software engineers?\
How does the grading system work in FANG?\
What are the grading standards in Google?\
Also it's not enough to solve the problem; you also need to pay attention to other important factors:

* Questions clarifications
* Upfront estimation and options
* Edge cases and exceptions
* Sub functions and main function
* Test cases
* Time and space complexity
* Optimization
* Bug-free coding
* Miscellaneous
  1. coding style
  2. naming
  3. comments
  4. typing
  5. logical and maintainable

\
Additionally, some companies have their own special rounds or focuses. For example:

* Amazon, Uber like to interview the lower level design.
* TikTok and Amazon may present difficult OA questions.
* Certain small/mid-sized companies may focus on hands-on API development.
* Some companies are highly selective when it comes to making hiring decisions, such as Snowflake and TikTok.

<figure><img src="https://d2qikg3rnxq7n1.cloudfront.net/interviewquestions/247-feed-how-interview-is-graded-min.png" alt=""><figcaption></figcaption></figure>


# Google Software Engineer Interview Guide

### Interview Process

**𝗥𝗲𝗰𝗿𝘂𝗶𝘁𝗲𝗿 𝗣𝗿𝗲-𝘀𝗰𝗿𝗲𝗲𝗻** (20-30 mins) – Non-technical. Chat about your resume and background. Get ready to answer questions like Why Google? What's your biggest achievement? Why are you leaving your current job?<br>

**𝗧𝗲𝗰𝗵𝗻𝗶𝗰𝗮𝗹 𝗣𝗵𝗼𝗻𝗲 𝗦𝗰𝗿𝗲𝗲𝗻𝘀** (40-60 mins) – One or two phone screens with the hiring manager or a Google employee. You'll solve a coding question related to data structures and algorithms on a shared Google Doc. Some questions on your background.<br>

**𝗢𝗻𝘀𝗶𝘁𝗲 𝗟𝗼𝗼𝗽** (4-5 interviews) – coding and system design questions. Expect questions related to slightly harder data structure, algorithms, and system design.

<figure><img src="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkG5BmeTljwaNO1WnSJpQ%2Fuploads%2FYLVIFtWT1Ab8JtQINC3K%2Fg-careers.png?alt=media&#x26;token=c8720192-c2cf-4774-a9d7-682c35e6eb19" alt=""><figcaption></figcaption></figure>

#### Google evaluates candidates on 4 criteria:

𝟭) 𝗚𝗼𝗼𝗴𝗹𝗲𝘆𝗻𝗲𝘀𝘀

Googleyness means putting the user first, being friendly, approachable, humble, doing something nice for others, being proactive, and keeping your eye on the goal. You'll be judged for being a team player and having a bias for action.<br>

𝟮) 𝗚𝗲𝗻𝗲𝗿𝗮𝗹 𝗖𝗼𝗴𝗻𝗶𝘁𝗶𝘃𝗲 𝗔𝗯𝗶𝗹𝗶𝘁𝘆

Your ability to solve problems and explain your thought process. Expect open-ended questions like how would you optimize this further? The interviewer wants to know how you learn and adapt to a situation.

𝟯) 𝗟𝗲𝗮𝗱𝗲𝗿𝘀𝗵𝗶𝗽

Your ability to take on tough problems and step back when it's not needed. They'll gauge if you can mobilize a team to solve a difficult problem. Get ready to answer questions like, how have you demonstrated leadership when you weren't the manager? how have you dealt with trade-offs and ambiguity?<br>

𝟰) 𝗥𝗼𝗹𝗲-𝗿𝗲𝗹𝗮𝘁𝗲𝗱 𝗞𝗻𝗼𝘄𝗹𝗲𝗱𝗴𝗲

Is your technical expertise sufficient to drive impact at Google? How will you grow and scale with Google?

#### <img src="/files/seGnazEqJ62RZLK6W8x8" alt="" data-size="line"> Interview Tips&#x20;

* **Data Structures** - Practice Heaps, HashTable, Tree, Stack, Queue, Graph, and Trie.&#x20;
* **Algorithm** - Practice Dynamic Programming, Quick-Sort, Breadth-first and Depth-first search.
* **Explain your thought process** - Practice describing your design decisions clearly and concisely.
* **Collaborate** – Don't forget to discuss tradeoffs, present multiple solutions, and take hints from the interviewer.

<figure><img src="/files/err1e2ViTchKfaGx6MmP" alt=""><figcaption></figcaption></figure>

#### Top recent Google tagged Coding Questions on LeetCode

Minimum Meeting Rooms (medium)

Number of Islands (medium)

Merge Intervals (medium)

Number of Closed Islands (medium)

Making a Large Island (hard)

Employee Free Time (hard)

Alien Dictionary (hard)

&#x20;&#x20;

#### Top System Design Questions

Design Web Crawler

Design Google Docs

Design Facebook Messenger

Design YouTube

Design Twitter/Facebook Message search

<br>

For detailed criteria for the interview grading of FAANG companies,

check out:

<https://book.aonecode.com/faang/mastering-the-faang-coding-interview-how-the-grading-system-works>


# Report On FAANG Salaries

Google and Netflix are the two from the FAANG companies that pay the highest average salaries to software engineers in the United States. FAANG companies do not ‌skimp on their salaries because of the value the software engineers bring to the company. Netflix even has a policy where they encourage their employees to interview different places and bring back the offers they get. If Netflix sees that they’re being outbid they’ll increase your salary and do the same for everyone across the company in similar roles.

<figure><img src="/files/uEnFxdCogDhEBel9oFih" alt=""><figcaption></figcaption></figure>

In this article, we analyzed the different specialties of a software engineer and FAANG software engineer salaries.

**Overview***:*

* The average salary for a software engineer at FAANG by role
* The average salary for a software engineer at FAANG by company
* FAANG software engineering salaries by company and seniority
* Software engineering salaries by location

## The average salary for a software engineer at FAANG

Let's check out some salary data for workers at FAANG companies, across five areas:

#### The average salary for a Front-end developer

| **Company** | **Annual Average** |
| ----------- | ------------------ |
| Amazon      | $120,043           |
| Google      | $115,000           |
| Meta        | $117,500           |
| Apple       | $106,000           |

**Cloud computing engineer**

| **Company** | **Annual Average** |
| ----------- | ------------------ |
| Amazon      | $105,559           |
| Google      | $140,430           |
| Apple       | $164,450           |

**Machine learning engineer/ data science engineer**

| **Company** | **Annual Average**                                     |
| ----------- | ------------------------------------------------------ |
| Amazon      | $131,664 (6% below the national average)               |
| Google      | $128,910                                               |
| Meta        | $153,046                                               |
| Apple       | $174,753                                               |
| Netflix     | $154,272 (15% higher than the national average salary) |

**Mobile engineer**

| **Company** | **Annual Average** |
| ----------- | ------------------ |
| Amazon      | $130,035           |
| Google      | $171,406           |
| Meta        | $131,017           |
| Apple       | $114,500           |

**Test and QA engineer**

| **Company** | **Annual Average**                                |
| ----------- | ------------------------------------------------- |
| Amazon      | $112,487                                          |
| Google      | $134,716                                          |
| Meta        | $133,431                                          |
| Apple       | $124,785                                          |
| Netflix     | $192,240 (151% above the national average salary) |

## FAANG software engineer salaries - by company and level

<figure><img src="/files/HMrSReTgURSgJAbYUaIS" alt=""><figcaption></figcaption></figure>

#### Amazon Software Engineering Salaries Across Levels:

| **Level**               | **Annual Average** |
| ----------------------- | ------------------ |
| SDE I \[New Grads Only] | $164,000           |
| SDE II                  | $225,000           |
| SDE III                 | $328,000           |
| Principal SDE           | $657,000           |

####

#### Google Software Engineering Salaries Across Levels:

| **Level** | **Annual Average** |
| --------- | ------------------ |
| L3        | $189,000           |
| L4        | $265,000           |
| L5        | $354,000           |
| L6        | $481,000           |
| L7        | $694,000           |
| L8        | $1,191,000         |

####

#### Apple Software Engineering Salaries Across Levels:

| **Level** | **Annual Average** |
| --------- | ------------------ |
| ICT2      | $173,000           |
| ICT3      | $217,000           |
| ICT4      | $317,000           |
| ICT5      | $442,000           |

####

#### Meta Software Engineering Salaries Across Levels:

| **Level** | **Annual Average** |
| --------- | ------------------ |
| E3        | $181,000           |
| E4        | $262,000           |
| E5        | $381,000           |
| E6        | $598,000           |
| E7        | $869,000           |
| E8        | $1,351,000         |

## Do you wanna earn FAANG level salaries ...?

If your answer is yes, then let’s read how AOneCode can help you do that.

You don’t have to be a genius to work at a FAANG company.

The hardest part is getting an interview. These companies receive so many applications that getting shortlisted for an interview requires your resume to showcase achievements and experience that are much better than other applicants. This can be hard to assess since you do not know how good (or bad) other applicants are relative to you. From our past experience, references/recommendations from a current employee will significantly boost your chances of landing an interview.

Once you are invited for an interview, it gets slightly easier. These companies have a very rigid interview process, usually spread over several rounds (each being progressively more difficult than the last). If you can come up with a process to tackle these interviews, you stand a good chance of getting an offer.

Getting past these interviews requires plenty of preparation. Even if you have like over 10 years of industry experience, you still wouldn’t even get past the phone screen for a FAANG company. **You need to prepare specifically for their interview process.**

Getting into these companies depends a lot more on your ability to crack their interviews than on your skills. It requires the right preparation. AOneCode can help you boost your interview skills, and direct you on what to focus on while preparing.


# Ace Your OOD Interview: Most Used Structural Design Patterns Simplified

The last post gave an introduction to low level design and Creational Design Patterns. In this article, let's take a look at Structural Design Patterns.

In the realm of software architecture, Low-Level Design Patterns hold a significant place, acting as blueprints for solving recurring design problems and enhancing code readability, modularity, and performance. Broadly, these patterns are grouped into three categories according to their purposes:

1. **Creational Patterns:** These patterns are all about class instantiation or object creation. They abstract the instantiation process and help make the system independent of how its objects are created, composed, and represented. (For further details, please refer to the previous post.)
2. **Structural Patterns:** Structural patterns concern class and object composition. They provide a manner to ensure that different parts of a system's structure work together efficiently, ensuring easy maintenance and a clear structure.
3. **Behavioral Patterns:** These patterns focus on communication between objects, how objects operate, and delegate responsibilities among them. They ensure that the entities in your application are well-communicated, efficient, and robust.

In this article, we'll delve into the realm of Structural Design Patterns. These include:

### **Adapter Pattern**

* Pros:
  * Allows classes with incompatible interfaces to work together.
  * Promotes reusability by adapting existing classes instead of modifying them.
  * Enhances flexibility and maintainability of code.
* Cons:
  * Can introduce an additional layer of complexity.
  * May lead to performance overhead due to the need for object wrapping.
* Use Cases:
  * Integrating legacy systems with new systems.
  * Interfacing with third-party libraries or APIs.
  * Making different classes collaborate in a unified way.

### **Facade Pattern**

* Pros:
  * Simplifies the usage of complex subsystems.
  * Provides a clear and concise interface for clients.
  * Promotes loose coupling and modularity.
* Cons:
  * Can hide important system details, potentially limiting customization.
  * May become bloated if the Facade interface grows too large.
* Use Cases:
  * Providing a high-level interface to a complex library or framework.
  * Creating a unified API for a group of related classes.
  * Simplifying the interaction with a subsystem.

### **Decorator Pattern**

* Pros:
  * Offers a flexible way to extend object behavior at runtime.
  * Allows for adding responsibilities without modifying existing code.
  * Supports the principle of open-closed design.
* Cons:
  * Can lead to a large number of small classes if used excessively.
  * May introduce complexity when dealing with deeply nested decorators.
* Use Cases:
  * Adding additional features or behaviors to an existing object dynamically.
  * Modifying object behavior without affecting other instances of the same class.
  * Providing optional or configurable enhancements to objects.

### **Proxy Pattern**

* Pros:
  * Adds a layer of indirection, enabling additional functionality.
  * Controls access to the original object, providing security or caching mechanisms.
  * Can improve performance by delaying the creation of expensive objects.
* Cons:
  * Can introduce a performance overhead due to the proxy layer.
  * May increase code complexity if not implemented carefully.
* Use Cases:
  * Implementing access control or authentication mechanisms.
  * Caching or lazy-loading expensive resources.
  * Implementing logging, auditing, or monitoring functionality.

### **Bridge Pattern**

* Pros:
  * Separates the abstraction from its implementation, promoting flexibility.
  * Allows the abstraction and implementation to evolve independently.
  * Enables runtime binding of different implementations.
* Cons:
  * Can introduce additional complexity, especially for simple scenarios.
  * Requires careful design to maintain a clear separation between abstraction and implementation.
* Use Cases:
  * Connecting different database technologies to a common interface.
  * Decoupling platform-specific code from the application logic.
  * Handling multiple display interfaces for a UI framework.

### **Composite Pattern**

* Pros:
  * Treats individual objects and compositions uniformly.
  * Simplifies the code by allowing the client to work with a single object or a collection of objects.
  * Supports recursive structures and hierarchical representations.
* Cons:
  * May not be suitable for all scenarios, especially when dealing with diverse object types.
  * Can have a performance impact when dealing with large composite structures.
* Use Cases:
  * Representing tree-like structures, such as directories and files.
  * Implementing menus, GUI components, or organizational hierarchies.
  * Performing operations on groups of objects uniformly.

### **Flyweight Pattern**

* Pros:
  * Reduces memory usage and improves performance by sharing common object parts.
  * Enables the creation and manipulation of a large number of similar objects efficiently.
  * Supports the efficient representation of immutable objects.
* Cons:
  * Requires careful management of shared state to avoid unintended side effects.
  * Can make the code more complex by introducing shared object pools.
* Use Cases:
  * Managing graphical objects in a drawing application.
  * Caching and reusing database connections or other expensive resources.
  * Storing shared data or configurations efficiently.

And more diagrams, analogies, and examples!&#x20;

### And More

<figure><img src="https://d2qikg3rnxq7n1.cloudfront.net/interviewquestions/532-low-level-design-interview-patterns.png" alt=""><figcaption></figcaption></figure>


# Object-Oriented Design Principles - SOLID

Who gets asked Low Level Design questions?\
Almost every leading payer (product company) has LLD rounds now, even freshers sometimes have LLD rounds.\
Companies: Amazon, Microsoft, Google & leading startups.

\
What is Low Level Design?\
Low Level Design (LLD), also known as Object Oriented Design (OOD), is a detailed description of all components, configurations, and processes of the software.\
Low Level Design focuses on the class-level design of a software and clean, fast, readable, maintainable, and extensible code.

**The Expectations of LLD interviews**

An LLD Interview evaluates your skill on creating modular, flexible, maintainable and reusable software, by applying Object-oriented Design Principles and Design Patterns.

LLD questions like,

***Design a Parking Lot,***

***Design a Tic-tac-toe Game,***

***Design a Ticketing System***

***...***

in the **class-level**, are intentionally unstructured and open-ended and they don't have a standard answer.

**How to Prepare for the LLD Interview**

1. Learn an object-oriented language ( C++ / Java / Python or C# )
2. Study about the **SOLID** and other Object Oriented Principles
3. Learn all the common **Design Patterns** and their applications
4. Explore some open-source projects and try to understand the best practices
5. Practice common LLD interview questions

LLD Principles

The object-oriented design principles are also called **SOLID**.

The main goal of these principles is to make software resilient to changes and easy to extend and maintain...

<figure><img src="https://d2qikg3rnxq7n1.cloudfront.net/interviewquestions/530-ood-low-level-design-interview-1-high.png" alt=""><figcaption></figcaption></figure>


