All Posts

Leetcode 169: Majority Element

Given an array nums of size n, return the majority element. The majority element is the element that appears more than n // 2 times. You may assume that the majority element always exists in the array.

Leetcode 229: Majority Element II

Given an integer array, find all elements that appear more than ⌊n/3⌋ times, where n is the length of the array. Your task is to return a list of all such elements.

Leetcode 347: Top K Frequent Elements

Given an integer array nums and an integer k, return the k most frequent elements from the array. The answer may be returned in any order.

Leetcode 383: Ransom Note

Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine. Each letter in magazine can only be used once.

Leetcode 387: First Unique Character in a String

Given a string s, find the index of the first character that does not repeat in the string. If all characters repeat, return -1.

Leetcode 451: Sort Characters By Frequency

Given a string, sort its characters based on their frequency of occurrence in descending order. If multiple solutions are possible, any valid answer is acceptable. The frequency of each character refers to how many times it appears in the string.