Sort from start point, update the end point based on minimum end point each iteration,8:08 if the 3rd point is within the range of 1st point but is lesser than 1st and 2nd point's minimum end point then it will be considered seperately for another arrow
@abhaykumar96128 ай бұрын
bro it can also be solved by sorting on the basis of starting point
@coderunner7438 ай бұрын
thanks bro. today i solved my first interval based question by myself successfully because of your yesterday POTD explanation video. here is my code based on sorting on the starting point class Solution { public int findMinArrowShots(int[][] points) { int n = points.length; Arrays.sort(points, (a, b) -> Integer.compare(a[0], b[0])); int arrows = 0; int i = 0; while (i < n) { int end = points[i][1]; int j = i + 1; while (j < n && points[j][0]
@atharvasuryawanshi76754 ай бұрын
Bhai faltu bakwas jyada karta he
@nerdInsaan8 ай бұрын
Just after seeing the number lines I got the logic , below is my code class Solution { public int findMinArrowShots(int[][] points) { Arrays.sort(points, Comparator.comparingInt((int[] arr) -> arr[0]).thenComparingInt(arr -> arr[1])); int itr = 0; int len = points.length; int [] prev = points[itr++]; int count = 1; while(itr < len){ if(prev[1] >= points[itr][0]){ prev[0] = Math.min(prev[0],points[itr][0]); prev[1] = Math.min(prev[1],points[itr][1]); itr++; } else { prev = points[itr++]; count++; } } return count; } } P.S. we can also do the same by sorting by starting point with minimal change of taking min of ending of both the points ( If someone didn't get then use notebook and dry run then you got the point)
@sivalokesh39978 ай бұрын
me being too lazy stored all these in ans[][] & returned it's size. 🙃