https://www.geeksforgeeks.org/find-position-element-sorted-array-infinite-numbers/ Understanding the Problem Problem Description: You are given a sorted and infinite array A[] and an element K. You need to search for the element K in the array. If found, return the index of the element, else return -1. For Example : Input: A[] = {1,3,5,8,12,13,17,19,28,39,103,123,140,2040,…}, K = 17 Output: 6 Input: A[] = {10,20,25,30,67,93,159,192,350,1230,1341,4533,…}, K = 23 Output: -1 Possible questions to ask the interviewer:- What is the meaning of infinite array ? ( Ans : We don't know the upper bound of the array) How big can the resultant index be? ( Ans: Ignore the integer overflow problem, we just want to check your logic, let us assume integer overflow won’t occur) Brute force and Efficient solutions We will be discussing three solutions for this problem:- Brute Force approach : Using linear Search Increment by a constant value and using binary search...
Comments
Post a Comment