Minimum Number of Bullets required to penetrate all bricks | Java program for above approach ; Function to find the minimum number of bullets required to penetrate all bricks ; Sort the points in ascending order ; Check if there are no points ; Iterate through all the points ; Increase the count ; Return the count ; Driver code ; Given coordinates of bricks ; Function call
import java . util . * ; class GFG { static int findMinBulletShots ( int [ ] [ ] points ) { Arrays . sort ( points , ( a , b ) -> a [ 1 ] - b [ 1 ] ) ; if ( points . length == 0 ) return 0 ; int cnt = 1 ; int curr = points [ 0 ] [ 1 ] ; for ( int j = 1 ; j < points . length ; j ++ ) { if ( curr < points [ j ] [ 0 ] ) { cnt ++ ; curr = points [ j ] [ 1 ] ; } } return cnt ; } public static void main ( String [ ] args ) { int [ ] [ ] bricks = { { 5000 , 900000 } , { 1 , 100 } , { 150 , 499 } } ; System . out . print ( findMinBulletShots ( bricks ) ) ; } }