We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi. The problem asks us to save a bunch of lists and perform queries on them. How would we represent 1 list? Well, an ArrayList<Integer> is a good choice instead of an int[] since we don't know the final size our list needs to be.
Now that we know how to represent 1 list, how should we represent a bunch of lists? Well, we can use an ArrayList<ArrayList<Integer>>, which is basically a list of lists. Creating this data structure is the main challenging part of this problem.
The rest of the code just performs the 2 types of queries on our data structure.
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
Hi. The problem asks us to save a bunch of lists and perform queries on them. How would we represent 1 list? Well, an ArrayList<Integer> is a good choice instead of an int[] since we don't know the final size our list needs to be.
Now that we know how to represent 1 list, how should we represent a bunch of lists? Well, we can use an ArrayList<ArrayList<Integer>>, which is basically a list of lists. Creating this data structure is the main challenging part of this problem.
The rest of the code just performs the 2 types of queries on our data structure.
HackerRank solutions.