akshat11's blog

By akshat11, history, 3 years ago, In English

Problem link — https://leetcode.com/problems/furthest-building-you-can-reach/

I am able to come up with the solution after some time but I still don't know and am not able to debug why my previous solution giving wrong answer for particular test case.Could anyone help me to figure it out?

code:

https://leetcode.com/submissions/detail/727643769/

  • Vote: I like it
  • -4
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You can do this using binary search.

https://leetcode.com/submissions/detail/727789686/

Indentation might be a bit messed up, I wrote this on my phone.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Consider the case:

heights = [1, 5, 6, 7] bricks = 2 ladders = 0

Your code returns 2. But with only two bricks you cant even move a single building. So the correct answer would be 0.