classSolution{public:intjump(vector<int>&nums){intans=0;intend=0;intfarthest=0;// Implicit BFSfor(inti=0;i<nums.size()-1;++i){farthest=max(farthest,i+nums[i]);if(farthest>=nums.size()-1){++ans;break;}if(i==end){// Visited all the items on the current level++ans;// Increment the levelend=farthest;// Make the queue size for the next level}}returnans;}};
classSolution{publicintjump(int[]nums){intans=0;intend=0;intfarthest=0;// Implicit BFSfor(inti=0;i<nums.length-1;++i){farthest=Math.max(farthest,i+nums[i]);if(farthest>=nums.length-1){++ans;break;}if(i==end){// Visited all the items on the current level++ans;// Increment the levelend=farthest;// Make the queue size for the next level}}returnans;}}
classSolution:defjump(self,nums:List[int])->int:ans=0end=0farthest=0# Implicit BFSforiinrange(len(nums)-1):farthest=max(farthest,i+nums[i])iffarthest>=len(nums)-1:ans+=1breakifi==end:# Visited all the items on the current levelans+=1# Increment the levelend=farthest# Make the queue size for the next levelreturnans