Java implementation for the above approach
import java . util . * ; class GFG { static boolean check ( int [ ] bananas , int mid_val , int H ) { int time = 0 ; for ( int i = 0 ; i < bananas . length ; i ++ ) {