We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The Hurdle Race
The Hurdle Race
+ 0 comments Using C++
int n = height.size(); int maxi = INT_MIN; //find the maximum in the array for(int i=0;i<n;i++){ maxi = max(maxi,height[i]); } if(k>maxi){ return 0; }else{ return maxi - k; }
+ 0 comments One of the possible way to do it Golang
func hurdleRace(k int32, height []int32) int32 { var max int32 = -1 var canJumpAllHurdles bool = true for i := 0; i < len(height); i++ { if k < height[i] { canJumpAllHurdles = false } if height[i] >= max { max = height[i] } } if canJumpAllHurdles { return 0 } return max - k }
+ 0 comments def hurdleRace(k, height): hurdle = max(height) if hurdle > k: return hurdle - k else: return 0
+ 0 comments return 0 if max(height)-k <=0 else max(height)-k
+ 0 comments C# Code-
int maxHeight= height.Max(); if(k<maxHeight)//needs potion to jump { int potion = maxHeight-k; return potion; } else{ return 0; }
Load more conversations
Sort 1320 Discussions, By:
Please Login in order to post a comment