# ARTS Week 26

3 min readFeb 20, 2022

--

# Algorithm

This week’s LeetCode problem is 215. Kth Largest Element in an Array

Given an integer array `nums` and an integer `k`, return the kth largest element in the array.

Note that it is the kth largest element in the sorted order, not the kth distinct element.

The kth largest element can be searched using the small top heap, and a small top heap with no more than K elements is maintained. Traverse the array, if the number of elements in the heap is less than K, add the array elements to the heap, and adjust the heap; if the number of elements in the heap is K, if the current element is greater than the for-element, remove the top element of the heap, and set the current Elements are added to the heap, and the heap is adjusted until the end of the array traversal.

`Input: nums = [3,2,1,5,6,4], k = 2Output: 5class Solution {    public int findKthLargest(int[] nums, int k) {        PriorityQueue<Integer> pq = new PriorityQueue<>();        for (int i = 0; i < nums.length; i++) {            if (i < k) {                pq.offer(nums[i]);            } else if (i >= k && nums[i] > pq.peek()) {                pq.poll();                pq.offer(nums[i]);            } else {                continue;            }        }        return pq.peek();    }}`

# Review

This week’s Review is for the following article: How to Start a Successful Freelance Business as a Software Developer

First of all, you need to figure out how much time you plan to devote to freelancing, whether it is a full-time job or a part-time job. When freelancing is your only source of income, this is a completely different concept than when you use it as additional income. Here are some suggestions from the author:

• Forget Business Cards and a Portfolio Site. The first thing you need to do is how to increase awareness and build a personal brand, not a business card and a personal website so your customers can find you.
• Networking Is the Most Important Thing You Can Do. You need to build your own social network so that you can find your potential customers more effectively.
• Beware of Freelance Platforms, They Are Evil. If a platform surveils access to your personal information by violating your privacy, it’s not good for you or the customer, so say “no” to those.
• Say ‘Hello World’ in Real Life. If you are in college, make more friends; go to local gatherings in related fields, and try to meet more collaborators at the gatherings; contact more local businesses and tell them that you can help.

# Tip

In C language, the difference between `r+`, `w+`, `a+` flags when opening a file:

• `r+`: support both read and write; but open will fail when the file does not exist; `fseek` can be used to adjust read and write offsets
• `w+`: supports both reading and writing; but when the file does not exist, it will create a file and then open it; `fseek` can only be used to adjust the read offset
• `a+`: supports both reading and writing; but when the file does not exist, it will create a file and then open it; `fseek` can only be used to adjust the read offset, and only write when writing to the end of the file

# Share

I have been on the road this week, without much thinking, the life in the future will gradually be on the right track, come step by step.

--

--

A programmer. Share knowledge of programming, operating system, Linux kernel, and reading, thinking etc. Let us maintain a beginner mend and grow together!