Skip to main content

Posts

Showing posts with the label array

You have given an array in which numbers are first increasing and then decreasing. Find the maximum element in O(log n).

An integer array with unique elements has the following property – elements initially are in increasing order till a point after which they start to decrease. Implement a function to find the index of the maximum element in the array in less than linear time, i.e., O(n). Example: Input: array = {1, 3, 5, 7, 9, 8, 6, 4} Output: max index = 4 Max Index : 4.  Max Element value is : 9

Interview Experience in a search based tech start up

once  i had an interview with a tech startup;  there were few programming problems; i am sharing one from that interview. Interview Location :Bangalore Company : A product based start up that works on search and big data. Round : 2 nd Level: semi difficult Program & Algo written on : white board Problem statement:   Given an array like A B C A A Z K I A Z Sort   the array based on frequency of character, if frequency is same sort them based on ASCII. {a=4,b=1,c=1,z=2,k=1,i=1} Out put : A A A A Z Z B C I K What i did  during that interview i am writing here: Algo To solve the problem:              1. Find their frequency  using hashtable.       2.  Prepare a class with {data : frequency } and put them in a list.       3. S...

Double check locking

Simple simulation of  muli-threading : few threads will read data from different sources and reduce them to get maximum from all the sources, An example of double check locking. lets make a  prototype of above problem. we will not go and solve it for generic case, we will simply create two thread thread1 and thread2;  this two threads will read data from two different sources and will will use a shared variable to get maximum of two data sets.  we will not go into details about what is singleton and double check locking, may be we see them in future post. in a sentence singleton is a design pattern that enable us to have only one     instantiation  of an object. that means we can't create  object of that class using new when and when ever we need to have object. So, our implementation logic goes as follows       1. start both the threads               find the max in each ...