Virtual Boolean Array
Implement a boolean array which implements the following methods:
BooleanArray()which initializes an array of size2 ** 31with all false values.void setTrue(int i)which sets the value at indexito true.void setFalse(int i)which sets the value at indexito false.void setAllTrue()which sets the value at every index to true.void setAllFalse()which sets the value at every index to false.boolean getValue(int i)which returns the value at indexi.
Constraints
0 ≤ n ≤ 100,000wherenis the number of method calls
https://binarysearch.com/problems/Virtual-Boolean-Array
Examples
Example 1
Input
- methods =
['constructor', 'getValue', 'setAllTrue', 'getValue', 'setFalse', 'getValue'] - arguments =
[[], [9], [], [3], [4], [4]]
Output
- answer =
[None, False, None, True, None, False]
Explanation
a = BooleanArray()
a.getValue(9) == False
a.setAllTrue()
a.getValue(3) == True
a.setFalse(4)
a.getValue(4) == False
Example 2
Input
- methods =
['constructor', 'setTrue', 'getValue', 'setFalse', 'getValue'] - arguments =
[[], [5], [5], [5], [5]]
Output
- answer =
[None, None, True, None, False]
Explanation
a = BooleanArray()
a.setTrue(5)
a.getValue(5) == True
a.setFalse(5)
a.getValue(5) == False
Leave a comment