Popular posts from this blog
Given two sorted arrays of size m and n .Find the number of common elements in them and also find what are that common elements.
This can be done in 3 ways :(considering worst case)//only for sorted 1. O(m*n) // if m == n, then (n*n) 2. O(nLog(m))// if m>n else O(mLog(n)) Using Binary search 3. O(m + n) // this is optimal worst case time// using concept of merge sort for example : array a[] = { 10,20,30.40,50,60,70,80,90};//only for sorted array b[] = { 10,15,20,25,30}; output : 10 20 30 number of same elements : 3 follow me on : Instagram Twitter LinkedIn my website facebook Whatsapp gmail
EV Minimize Array Cost asked in Infosys- march 2022 (available in c++ only)
EV_Minimize Array Cost connect with me on Facebook Twitter Instagram Github Youtube len(arr)-1 Σ(arri-arri-1)² i=1 len(arr) is the size of the array. Insert any integer at any location of the array such that the cost of the array is minimized. Find the minimum possible cost of the array after inserting exactly one element. Example a= [1, 3, 5, 2, 10] The cost of the array before insertion =(1-37+(3-57+(5-2)²+(2-102²= 81. Two of many scenarios are shown below. 1. Insert 4 between 3 and 5, cost of array = (1-37+(3-47+(4-57+(5-2)²+(2 107²2² = 79. 2. Insert 6 between 2 and 10, cost of array =(1-37+(3-5)+(5-27²+(2-67² + (6 107² = 49. It can be proven that 49 is the minimum cost possib...
Comments
Post a Comment