Write an optimized solution for following problem(not needed to write as pseudoc
ID: 3747716 • Letter: W
Question
Write an optimized solution for following problem(not needed to write as pseudocode or actual code). You have given a list(array) with millions entries in it. The list is not sorted, but this is special list, which contains all entries in incremental order and at some point, it start decreasing. How to find that fluctuation point index? e.g test [-98,-87,..0,1,2,3,4,... 50,1000000,..1111001111, 10,9,8,7,0-3,-2 For above list fluctuation point is number (10) at index n. NOTE: list can contain duplicate numbers.Explanation / Answer
ANSWER: As per your requirement you do not want a pseudocode or code for this problem here I am giving you the solution for this problem which can find fluctuation point in O(n) time complexity.
IDEA----> Here as we know that list is in increasing order so we have to iterate the list from the beginning and check for the next element of the list if it is greater than the previous element of the list then it will be the fluctuation of this list. as :
int variable;
for(int i=0;i< list.size(); i++)
{
if(list[ i+1] >list[ i] ) {
variable= list[ i+1]
break; }
}
here variable contains your fluctuation point.
If you have any problem with this solution please comment or like it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.