Searching Problem List

Interpolation Search. Youtube. GFS.  The search works well for uniformly distributed numbers.  Formula Calculation - So the formula to estimate the position = pos = lo + [ (x-arr[lo])*(hi-lo) / (arr[hi]-arr[Lo]) ] arr[] ==> Array where elements need to be searched x ==> Element to be searched lo ==> Starting index in arr[] hi ==>… Continue reading Searching Problem List

Array Set 3

Array Set 1  Array Set 2 Given an array of of size n and a number k, find all elements that appear more than n/k times. GFG. Code. Brief Algo: We basically maintain an array which has keeps track of element and it's frequency. But we don't maintain the count of all the element. We… Continue reading Array Set 3

Array – Java

Very basic way to use java array - You can either use array declaration or array literal (but only when you declare and affect the variable right away, array literals cannot be used for re-assigning an array).For primitive types: int[] myIntArray = new int[3]; int[] myIntArray = {1,2,3}; int[] myIntArray = new int[]{1,2,3}; For classes,… Continue reading Array – Java

Array – Set 1

Array - Set 2  More Array Problems -  1 , 2 General Direction For Thinking for Array Problem – 1.  Brute force is the obvious one and should be instant response 2.  Sorting (multiple pointers when sorting is also useful | sometimes search after sort ) 3.  Hash When we are given condition like numbers are in… Continue reading Array – Set 1

Array Set 2

Array Set 1 [SKIP] Find the element that appears once Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once. Expected time complexity is O(n) and O(1) extra space. GFS Find a sorted subsequence of size 3 in linear time Given an array… Continue reading Array Set 2