Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Durga Pramodh Kumar Jajala
Question Needs More Clarification [ Root cause for incorrect solution]

Durga Pramodh Kumar Jajala

Mar 12, 2024

The question never states if the array is sorted in increasing or decreasing order. But then one of the test cases has an array in decreasing order. This breaks the logic of finding the closest value through binary search since the solution they provided, binary search algo assumes the array is increasing order.

Custom Testcase :

[12,10, 9,7,6,3,2,1] X= 4 ,K = 2

Expected Result:

[2,3] or [3,6]

Actual Result:

[9,10]

1

0

Comments
Comments
Shubham Vora
Shubham Voraa year ago

It is fixed!

On this page