Create a class of integer collection that supports add to all that adds a given number to all the elements in the collection at this point.
class AddToAllCollection {
public void append(int val) {
}
public int get(int index) {
}
public void addToAll(int val) {
}
}
All methods should work in O(1) time.
Follow-up:
Implement multipyToAll(int val) in O(1) time.