Write a C program to find turning number in an array. The problem is an interview questions. You have to find maximum number which increases at a certain index in an array and immediately decreases.

For example if the given array is {1, 2, 3, 4, 11, 8, 7, 6} , the turning number is 11. In Another example {1, 2, 3, 4, 11, 8, 7, 6,9,10,11,12,3,4} turning number is 12.

C program to Find Turning Number in an Array

Compile and run on Linux

The above implementation has time complexity : O(n)

More efficient way to write C program to Find Turning Number in an Array

The above solution can be modified to reduce time complexity of O(n) to time complexity of O(logn).

Ref:

https://gist.github.com/luckypapa/2240d5839795d380b1df




Related Contents to follow