i cannot think of the logic of this search algo. can u tell me how to approach this algo ?
Logic of staircase search
@Raghavsingla522 You can follow the following steps:
- Let the given element be x, create two variable i = 0, j = n-1 as index of row and column
- Run a loop until i < n && j>=0
- Check if the current element is greater than x then decrease the count of j. Exclude the current column.
- Check if the current element is less than x then increase the count of i. Exclude the current row.
- If the element is equal then print the position and end.