C++ | Assembly | OS | Open Source

## Intuition

• Set the first element arr[0] to 1.
• Limit the difference of two adjacent elements to 1 or less than 1, which means arr[i+1] is the same as arr[i] or equal to arr[i] + 1.
• Return the maximum possible value in arr.

## Approach

1. Set arr[0] to 1 (that’s the rule of this challenge).

2. Set max to 1, which represents the maximum possible value in arr is 1.

3. Sort arr in ascending order.

4. Iterate over arr from the second element arr[1] (because arr[0] has already been set to 1):

1. Set arr[i] to max if it’s the same as or higher than max, then increase max by 1.
2. Do nothing if arr[i] is smaller than max (which couldn’t happen because arr has already been sorted in ascending order).
5. Return max.

Pseudocode of maximumElementAfterDecrementingAndRearranging:

## Complexity

• Time complexity: $O(nlogn)$.

• Sorting arr in ascending order is $O(nlogn)$.
• Iterate over arr to update arr and max is $O(n)$.
• Overall complexity is $O(nlogn)$.
• $n$ is the total size of arr.
• Space complexity: $O(1)$.

## Background of the Problems

I’ve enrolled in a course whose main content is AVR assembly language this semester. In the lab of this course, we have to use an IDE called Microchip Studio (aka. Atmel Studio) to develop, debug, and test AVR assembler programs. Since I mainly use macOS and Microchip Studio supports only Windows, I need to use this IDE with a Windows 11 virtual machine.

I used Parallels Desktop, the virtualization software that I mainly used, and its official wizard (Get Windows 11 from Microsoft) to create a Windows 11 VM, then successfully installed Microchip Studio in it. However, I encountered some weird problems when I started using Microchip Studio.

## What the Problems are

### A Warning was Generated on Startup

A warning is generated every time Microchip Studio starts.

## 问题的表现

### 界面布局怪异

I chose not to follow Cloud Native for several reasons, and I found that Cloud Native is not as powerful as I used to believe. It’s not a “silver bullet”, and I don’t need to stick to it.

# How did I know Cloud Native

I was passionate about Spring Cloud Alibaba-based microservices before April 2020 because it’s really easy to use it to develop faultless microservices. I developed a Spring Cloud Alibaba-based project to participate in a software development competition. However, after I transferred the microservices into Docker containers and used Kubernetes (K8S) to manage them, I found Kubernetes and Spring Cloud could not work together: some functionalities (like Nacos and ApiServer, Spring Cloud Gateway and Ingress) overlapped and caused incompatibility between them. There were so many conflicts that the entire project couldn’t work properly.

That failure reminded me that I didn’t know enough about Spring Cloud and Kubernetes. After searching for a lot of information, I realized that Spring Cloud is a framework for building “traditional” microservices, which are not so suitable for Kubernetes unless using Spring Cloud Kubernetes. I also learned about a new technology called “Service Mesh” and a new theory related to Service Mesh called “Cloud Native” when collecting information related to K8S.

It was a little hard for me to understand service mesh and Cloud Native then, but after I read some articles and books related to them, I finally knew what they were and what their advantages were. Suddenly, I felt that “traditional” microservices were outdated because they depended a lot on SDKs. Many basic functionalities, like service discovery and resource management, are provided by SDKs, which are coupled with service codes. What’s worse, the service codes need to be changed every time the SDKs make destructive updates. Service mesh provides a better solution: refactor those basic functionalities into a separate process or container that runs with (in the same Pod) the microservice container. Service mesh amazed me and solved my problems with microservices completely.

# Cloud Native is my favorite theory ever

Service mesh piqued my interest in Cloud Native. I found that it’s an attractive theory that everyone holds their own opinion on it. Though it’s so abstract that I still can’t fully understand it, I kept studying and following Cloud Native from 2020 to 2022. I decided I needed to get a job related to Cloud Native (such as Cloud Native Engineer, Site Reliability Engineer, and Basic Software Developer). So I chose Golang as the programming language I mainly used and studied a lot about Docker, Kubernetes, and Istio. I never missed every conference about Cloud Native and service mesh that I was able to attend then. I don’t think it’s a successful choice, but in addition to learning how to use Cloud Native tools and their inner workings, I also learned a lot about software design and software architecture.

Looking back to that time now, I can confidently say that “Cloud Native is my favorite theory ever”.

# 云原生，我曾经最爱的理论

Service Mesh 引起了我对于云原生的兴趣。我发现云原生是一种引人注目的理论，并且一千个人眼中有一千种云原生。即使云原生如此抽象，以至于我至今都无法完全理解它，但我仍然在 2020 到 2022 年间持续学习它。我决定要从事与云原生相关的工作（例如云原生工程师、SRE、基础软件工程师等），所以我选择了 Go 语言作为我主要使用的编程语言，并且深入学习了 Docker、K8S 和 Istio，还没有错过任何一场我可以参加的有关于云原生和 Service Mesh 的会议。我并不认为这是一个成功的选择，不过我除了学习使用这些云原生工具以及它们的原理之外，还学到了大量软件设计和软件架构的知识。

This is the very first program I developed.
Just like me, most programmers’ very first program is to print “Hello world” in the terminal.
Then, it’s the most suitable title for the very first article I write after I’ve started a completely new life.

# A destroyed “game account”

Do you have such an experience: you destroy your character or account in a game, so you must create a new character or register a new account and start from zero? I had such an experience, but the thing that I destroyed was not my character or account in a game; it was my life.

In 2022, I’ve chosen Golang as the programming language that I mostly use and Site Reliability Engineer as my job. I didn’t know that that was the worst decision I’ve made in my life. That doesn’t mean Golang is a terrible language or that SRE is a bad job for a programmer. They are just not suitable for a fresh graduate. You probably know that the status of a fresh graduate is really important in China because there’s a special opportunity for fresh graduates to be hired by companies in China regardless of work experience. But SRE is a job that requires a lot of experience, and Golang is a new programming language that also requires 3-5 years of experience in other languages. So, it’s really hard for a programmer who doesn’t have more than 3 years of experience to become a SRE using Golang in China; the chances are really limited.

Fortunately, I finally got a job at a big international company as a SRE with a satisfactory salary. I worked hard, developed a lot of important features, solved many complicated bugs alone, and became an indispensable member of the SRE team. That’s the happiest 8 months of my life: my job became a part of my life, I live in a big city where everything is convenient and enjoyable, and I never need to work overtime. I feel happy every time I remember that time.

The good times didn’t last long. I’ve lost my job because my department and group were abolished due to the company’s poor decision-making. I tried to find a new job as an SRE and asked over 400 companies, but I wasn’t given a single chance to interview because I only have 8 months of experience and I’m not a fresh graduate anymore. I was rejected by every company simply because of my experience, regardless of my strong programming skills and my ability to work as an experienced programmer.

0%