Leetcode Progress
Concatenation of Array
Problem Statement
Concatenate two arrays side by side
Contains Duplicate
Problem Statement
Check if an input array contains duplicate elements
Valid Anagram
Problem Statement
Check if two input strings are anagrams of each other
Two Sum
Problem Statement
Given an array of integers, return the indices of the two numbers such that they add up to a specific target.
Longest Common Prefix
Problem Statement
Write a function to find the longest common prefix string amongst an array of strings.
Group Anagrams
Problem Statement
Given an array of strings, group the anagrams together such that the output is a list of lists of anagrams.
eg. Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”] Output: [[“bat”],[“nat”,“tan”],[“ate”,“eat”,“tea”]]
Remove Element
Problem Statement
Given an array and a certain value, remove all instances of that value in-place and return the new length.
Top K Frequent Elements
Problem Statement
Given a non-empty array of integers, return the k most frequent elements.
Majority Element
Problem Statement
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
Design Hashset
Problem Statement
Design a HashSet without using any built-in hash table libraries.
Implement MyHashSet class:
void add(key) Inserts the value key into the HashSet.
bool contains(key) Returns whether the value key exists in the HashSet or not.
void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.
Input: ["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"]
[[], [1], [2], [1], [3], [2], [2], [2], [2]]
Output: [null, null, null, true, false, null, true, null, false]
Sort Colors
Problem Statement
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
You can use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Input: [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Encode and Decode List of strings
Problem Statement
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings.
Implement the `encode` and `decode` methods.
Input: ["Hello","World"]
Output: ["Hello","World"]