Skip to content

Commit c3d74fc

Browse files
committed
Runtime: 147 ms (Top 48.60%) | Memory: 103.8 MB (Top 70.82%)
1 parent 1841968 commit c3d74fc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/J/Jump Game IV/Jump Game IV.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 147 ms (Top 48.60%) | Memory: 103.8 MB (Top 70.82%)
12
/*
23
Here we are using map and queue
34
map for storing the array elements and where are the other indices of the same element
@@ -9,20 +10,20 @@
910
i> check the next index (i+1)
1011
ii> check the previous index(i-1)
1112
iii> check all the indices of the list whih are present in the map
12-
once these three things have been done we will
13+
once these three things have been done we will
1314
remove the element that is arr[i]
1415
because if we did not remove it we are going to do the same repeated task over and over again
1516
and this will result in stack overflow
16-
so it is important to remove the indices which have been visited once
17+
so it is important to remove the indices which have been visited once
1718
every time we check the queue we incease the answer because viewing a queue means that
18-
we are not at the last index
19+
we are not at the last index
1920
2021
I hope the idea was clear :) you'll understand better when you see the code
2122
*/
2223
class Solution {
2324
public int minJumps(int[] arr) {
2425
int n = arr.length;
25-
26+
2627
if(n <= 1) return 0;
2728
Map<Integer, List<Integer>> mp = new HashMap<>();
2829
for(int i = 0;i < arr.length ; i++) {
@@ -67,4 +68,4 @@ public int minJumps(int[] arr) {
6768
}
6869
return ans;
6970
}
70-
}
71+
}

0 commit comments

Comments
 (0)