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.
- Prepare
- Java
- Data Structures
- Java Arraylist
- Discussions
Java Arraylist
Java Arraylist
Sort by
recency
|
809 Discussions
|
Please Login in order to post a comment
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc = new Scanner(System.in); ArrayList> list = new ArrayList<>(); int n = sc.nextInt();
Isnt it kinda weird that the author seem to mean index 0 in their queries but uses "1" instead, e.g., for query 1 3 we actually mean the first list (1). It means that we need to shift the index so that when we assign int x to the value, it should be x = value -1 (and int y = value -1).
Its not wrong, it just felt like adding an unneccesary layer of complexity. Perhaps its part of the exercise, i could also misunderstand the reasoning behind it.
The solution, as i see it is to shift the lists in both images and in the tests, so images show lists 0, 1, 2, 3 ,4 ... instead of 1,2,3,4,,, and so the test doesnt expect the list in place 1 but rather in place 0
import java.io.; import java.util.; import java.util.Scanner; public class Solution {
}
import java.io.; import java.util.;
public class Solution {
}