ArrayList notes
ArrayList notes
ArrayLists
Today’s checklist
1. Basic of 2D Arrays
2. Problems based on 2D Arrays
3. 2D ArrayList
4. ArrayList vs Arrays
5. Basic STL functions of ArrayList
6. Problem based on 2-D ArrayList
What and Why?
is matrix
2D Array - is a
grid ,
it
Representation of 2D array
Declaration of a 2-Dimensional
Array
int[][] arr = new int[4][2];
[Leetcode 867]
-
Ques:
Q7 : Write a program to rotate the matrix by 90 degrees
clockwise.
[Leetcode 48]
Ques:
Q7 : Write a program to rotate the matrix by 90 degrees
clockwise.
[Leetcode 48]
Ques:
Q8 : Write a program to print the matrix in wave form.
0 1 2
1 2 3
0
4 5 6
1
7 8 9
2
0
Ques:
Q9 : Write a program to print the matrix in spiral form.
0 1 2
1 2 3
0
4 5 6
1
7 8 9
2
0
[Leetcode 54]
2D ArrayList
● List<List<Integer>> v = new ArrayList<>();
● List<List<Integer>> v = new ArrayList<>(m);
List<List<Integer>> v = new ArrayList<>(m);
for (int i = 0; i < m; i++) {
v.add(new ArrayList<>(n));
}
Advantages of ArrayList over
arrays
Basic STL functions in ArrayList
● add()
● remove()
● get()
● size()
● clear()
● isEmpty()
● Contains()
● indexOf()
● toArray()
·
10
3 ot
01 2
(40 503 a = 23d = 2003
a =
<10 ,
20
, 303 b =
,
e =
2210 ,
20 , 303 ,
suoisos 33,
, 25033
Ques:
Q10 : Given an integer ‘numRows’, generate Pascal's
triangle.
[Leetcode 118]
Ques:
Q11 : Write a program to print the multiplication of two
matrices given by the user.
Ques:
Q11 : Write a program to print the multiplication of two
matrices given by the user.
Ques:
Q12 : Score after flipping matrix .
[Leetcode 861]
Ques:
Q12 : Score after flipping matrix .
[Leetcode 861]
Ques: 01 L 3
2
E
32
111 I
I W O I
+ I 11 I
-
[Leetcode 861]
Ques:
Q13 : Write an efficient algorithm that searches for a value target
in an m x n integer matrix which has the following properties :
● Integers in each row are sorted in ascending from left to right.
[Leetcode 240]
Ques:
Q14 : Given an m x n integer matrix matrix, if an element is
0, set its entire row and column to 0's.
2
0
[Leetcode 73]
THANK YOU