Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice. Given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them.
- Runtime: 92.26
- Memory: 66.24
You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number. You are given an integer array nums representing the data status of this set after the error. Find the number that occurs twice and the number that is missing and return them in the form of an array.
- Runtime: 20.20
- Memory: 5.96
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity?
- Runtime: 44.57
- Memory: 82.71
Write a program to find the node at which the intersection of two singly linked lists begins.
- Runtime: 76.92
- Memory: 88.00
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Solution: BFS
- Runtime: 97.89
- Memory: 36.25
A valid encoding of an array of words is any reference string s and array of indices indices such that:
-
words.length == indices.length
-
The reference string s ends with the '#' character.
-
For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i]. Given an array of words, return the length of the shortest reference string s possible of any valid encoding of words.
-
Runtime: 92.44
-
Memory: 51.74
Design a HashMap without using any built-in hash table libraries.
To be specific, your design should include these functions:
put(key, value) : Insert a (key, value) pair into the HashMap. If the value already exists in the HashMap, update the value. get(key): Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key. remove(key) : Remove the mapping for the value key if this map contains the mapping for the key.
*notes: Uses dict
- Runtime: 98.12
- 80.28