2147A - Shortest Increasing Path
I dont know if it is a good idea to use binary search to find if a valid break point can be set on x axis. although it passed all tests very fast. ~~~~~ left = 1 right = xi find = False while left <= right: mid = (left + right) // 2 if mid < yi and yi < xi — mid: find = True break else: right = mid — 1 if find: print(3) else: print(-1) ~~~~~









Where did the binary search come from? There are only 3 possible answers: -1, 2 and 3. You can watch the editorial for detailed explanation, but binary search isn't used here
binary search is overkill. you can just compare x and y in a certain way and solve it in a few if statements:
$$$x \lt y\implies \text{ans}=2$$$
$$$x \gt y+1\implies \text{ans}=3$$$
$$$\text{else } \text{ans}=-1$$$
if y == 1 => ans = -1
else if x<y => ans = 2
else if x>y+1 => ans = 3
else => ans = -1
this solution passed all test cases for me
one of ur cases should be -1 no?
yeah typo